Try this:

<?php

$a[2][100] = "foo";
$b[2][101] = "bar";

function array_join($a, $b) {

     $each = each($a);
     $key = $each['key'];

     $c[$key] = $a[$key] + $b[$key];

     return $c;
}

$c = array_join($a, $b);
print_r($c);

?>

--
Rajesh

RobsonAndJervis wrote:
> Hi all,
> 
> This may be a really simple question but what's the best way to 
> combine two 
> arrays such that indexes are preserved?
> 
> e.g. two arrays $a and $b have the structure
> 
> $a[2][100] = "foo";
> $b[2][101] = "bar";
> 
> I'd like to combine $a and $b such that the resulting array, $c, has 
> the 
> structure
> 
> $c[2][100] = "foo";
> $c[2][101] = "bar";
> 
> I've tried
> 
> $c = $a+$b;  // Problem: one value is overwritten
> $c = array_merge($a,$b); //Problem: indexes are not preserved but re-
> indexed
> $c = array_merge_recursive($a,$b); //Problem:  same as array_merge()
> 
> Any ideas?
> 
> Thanks,
> EC

Reply via email to