472,119 Members | 1,473 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 software developers and data experts.

Merging unknown arrays

Hi!

Is there a better way to do this?

$command = '$array = array_merge($array[\'' .
implode('\'],$array[\'',array_keys($array)) . '\']);';
eval($command);

Regards,
André
Jan 16 '06 #1
3 1705
André Hänsel said the following on 15/01/2006 23:57:
Hi!

Is there a better way to do this?

Well, you haven't said what "this" is - what are you trying to do?
$command = '$array = array_merge($array[\'' .
implode('\'],$array[\'',array_keys($array)) . '\']);';
eval($command);

From your code, I'm guessing that you want to convert an array of
arrays into a single array. How about:

$result = array();
foreach ($array as $a)
{
$result = array_merge($result, $a);
}

--
Oli
Jan 16 '06 #2
André Hänsel wrote:
Is there a better way to do this?

$command = '$array = array_merge($array[\'' .
implode('\'],$array[\'',array_keys($array)) . '\']);';
eval($command);


$array = array_values($array);
JW
Jan 16 '06 #3
$array = call_user_func_array('array_merge', $array);

Jan 16 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Tmenke | last post: by
3 posts views Thread by Maarten van Reeuwijk | last post: by
4 posts views Thread by Bush will disarm all workers next | last post: by
8 posts views Thread by vidishasharma | last post: by
5 posts views Thread by John | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.