FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » how to join two arrays?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: how to join two arrays? [message #185713 is a reply to message #185704] Sat, 03 May 2014 22:23 Go to previous messageGo to previous message
Denis McMahon is currently offline  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
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: count() problem
Next Topic: part two same issue - unwanted empty values in array
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 22 21:35:24 GMT 2024

Total time taken to generate the page: 0.04827 seconds