Re: how to join two arrays? [message #185710 is a reply to message #185704] |
Sat, 03 May 2014 20:07 |
J.O. Aho
Messages: 194 Registered: September 2010
Karma:
|
Senior Member |
|
|
On 03/05/14 19:25, richard wrote:
> I am building an array by scannning ten directories.
> With each scanned directory, the output is stored in one array.
> How do I properly join that array with a second array?
>
> Without duplicate keys!
>
> Array_merge works fine but keys are duplicated.
Keys are always unique, see example:
<?php
$a1 = array("a" => 1, "b" => 2, "c" => 3);
$a2 = array("a" => 10, "d" => 4, "e" => 5);
$a3 = array_merge($a1, $a2);
var_dump($a1);
var_dump($a2);
var_dump($a3);
echo $a3["a"]."\n";
?>
If you haven't named the cells, then it will just merge the arrays
(append one after the other).
--
//Aho
|
|
|