PHP duplicate Array key associated values count

<?php

$email = array('test@gmail.com','testinguser@gmail.com','testinguser@gmail.com');
$amt = array(10,51,18);


function array_combine_($keys, $values)
{
    $result = array();
    foreach ($keys as $i => $k) {
        $result[$k][] = $values[$i];
   
    }
   
    array_walk($result, create_function('&$v', '$v = (count($v) == 1)? array_pop($v): array_sum($v);'));
    return    $result;
}
$countval = (array_combine_($email, $amt));
//print_r($countval);

$array_keys = array_keys($countval);
$array_values = array_values($countval);
print_r($array_keys);
print_r($array_values);

Share this

Related Posts

Previous
Next Post »

Pageviews from the past week