469,344 Members | 6,578 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,344 developers. It's quick & easy.

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 1579
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
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.