Hi,
I know ways to join the arrays, but pretty ugly, prefer an optimized function of PHP. So the question is:
Is there a function for joining 2 array? and is it in PHP4 or PHP3?
Thanks
| SitePoint Sponsor |





Hi,
I know ways to join the arrays, but pretty ugly, prefer an optimized function of PHP. So the question is:
Is there a function for joining 2 array? and is it in PHP4 or PHP3?
Thanks
- Son Nguyen
AdSpeed.com - Ad Serving and Ad Management Made Easy





Son
array_merge() is what you are looking for I believe. Its a PHP4 function
Please don't PM me with questions.
Use the forums, that is what they are here for.





I'm currently on a PHP3 server, so any function like array_xx is unsupported!!! Thanks Freddy, have to ask for PHP4 now![]()
- Son Nguyen
AdSpeed.com - Ad Serving and Ad Management Made Easy





There is of course the long way to do it
for($i=0;$i<count($array2);$i++) {
$array1[count($array1)] = $array2[$i];
}
Please don't PM me with questions.
Use the forums, that is what they are here for.

Freddy, is there a reason why you use:
'$array1[count($array1)]'?
I tried
seems to work fine for me.Code:$foo = array(1,2); $bar = array(3,4); for($i=0;$i<=count($bar);$i++) { $foo[] = $bar[$i]; } //$foo now '1234'





It's the same thing Rob,
since every time you add a new entry, the call to count($array1) will increase by one, so it will always at the end.
- Son Nguyen
AdSpeed.com - Ad Serving and Ad Management Made Easy

I understand this, which is why I asked. It just seems a little inefficient do add the extra code?





Probably so I didn't have time to test and I just wanted make sure that the additions were gettiong the correct indexes
Please don't PM me with questions.
Use the forums, that is what they are here for.
Bookmarks