Array comparison

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Lets say i have these two arrays (PHP 4.3.3)

$arr_1 = array( [left]  => 22,  
        [up]    => 4,  
        [right] => 10  

$arr_2 = array( [bottom] => 13,  
        [up]     => 6,  
        [right]  => 12  

I need to get the new array which would look like this:

$arr = array( [left]   => 22,  
          [up]     => 10,  
          [right]  => 22,  
          [bottom] => 13

the thing is that i should put two arrays into one by this rules:
for same keys create one key with value of all values of that key
for different keys just create their key with their value

how to do it?

thank you very much

Re: Array comparison

friglob wrote:
Quoted text here. Click to load it

function callback(&$item) {
    if (is_array($item)) $item = array_sum($item);
$arr_3 = array_merge_recursive($arr_1, $arr_2);
array_walk($arr_3, 'callback');



Site Timeline