[PHP] Dynamic array_merge problem

2006-04-12 Thread Ace McKool
Hi,

This is the end result I'm trying to get:

$z1 = array_merge($z[0], $z[1], $z[2]);

But what if I don't know how many elements are in $z?  I tried this (but it
breaks if there are more than 2 elements in $z):

for ($i=0; $icount($z); $i++)
{
if ($i(count($z)-1))
{
$z1 = array_merge($z[$i], $z[$i+1]);
}
}

Any pointers would be greatly appreciated!  TIA


Re: [PHP] Dynamic array_merge problem

2006-04-12 Thread Pure Web Solution
Hi

if you just want to sort of concatenate your arrays then why not just loop
through the whole thing in order to get the new single array. Need more info
for further consideration.  Hope this helps!



for ($i=0;$icount($z);$i++){

  $z1[$i] = $z[$i]; 

}



Pure Web Solution
http://www.purewebsolution.co.uk
PHP, MYSQL, Web Design  Web Services


Ace McKool [EMAIL PROTECTED] wrote:

 Hi,
 
 This is the end result I'm trying to get:
 
 $z1 = array_merge($z[0], $z[1], $z[2]);
 
 But what if I don't know how many elements are in $z?  I tried this (but it
 breaks if there are more than 2 elements in $z):
 
 for ($i=0; $icount($z); $i++)
 {
 if ($i(count($z)-1))
 {
 $z1 = array_merge($z[$i], $z[$i+1]);
 }
 }
 
 Any pointers would be greatly appreciated!  TIA

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Dynamic array_merge problem

2006-04-12 Thread Ace McKool
This worked wonderfully--thank you very much Jochem!

On 4/12/06, Jochem Maas [EMAIL PROTECTED] wrote:

 Ace McKool wrote:
  Hi,
 
  This is the end result I'm trying to get:
 
  $z1 = array_merge($z[0], $z[1], $z[2]);

 $yourArrays = array($z[0], $z[1], $z[2]);
 $z1 = call_user_func_array('array_merge', $yourArrays);

 obviously - you have to build $yourArray before passing it
 to call_user_func_array()