Re: how to join two arrays? [message #185713 is a reply to message #185704] |
Sat, 03 May 2014 22:23 |
Denis McMahon
Messages: 634 Registered: September 2010
Karma:
|
Senior Member |
|
|
On Sat, 03 May 2014 13:25:10 -0400, 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.
scandir creates numerically indexed arrays. Merging these arrays will
create a larger numerically indexed array, eg if you merge two arrays
with keys [0] through [9], you end up with a single array with keys [0]
through [19].
eg if the first dir generated:
$arr1
[0] "."
[1] ".."
[2] "foo.bar"
[3] "really fubar"
and the second dir generated
$arr2
[0] "."
[1] ".."
[2] "bah bah.blacksheep"
[3] "fufu.fubar"
then: array_merge ( $arr1, $arr2 );
will generate:
[0] "."
[1] ".."
[2] "foo.bar"
[3] "really fubar"
[4] "."
[5] ".."
[6] "bah bah.blacksheep"
[7] "fufu.fubar"
How you then tell which file is where, that's your headache at this point.
--
Denis McMahon, denismfmcmahon(at)gmail(dot)com
|
|
|