eviltwinkie Posted June 28, 2006 Share Posted June 28, 2006 Very simple question which either I am smoking crack and therefore cannot see the answer...or is just impossible to do. Using PHP5...$array = [0] => Array ( [Misc] => Blah ) [1] => Array ( [Animals] => Moo ) [2] => Array ( [Animals] => Oink ) [3] => Array ( [Stuff] => Thing1 ) [4] => Array ( [Stuff] => Thing2 ) All I need to accomplish is to....$result = array_merge_recursive($array['0'],$array['1'],$array['2'],$array['3'],$array['4']);Which yields...$result = [Misc] => Blah [Animals] => Array ( [0] => Moo [1] => Oink ) [Stuff] => Array ( [0] => Thing1 [1] => Thing2 ) no problem there...however I do NOT know how many arrays I will need to list within the array_merge_recursive() function...so I tried to do a count and create a variable with the array broken into the proper format with the "," between them like...$variable = $array['0'],$array['1'],$array['2'],$array['3'],$array['4'];however array_merge_recursive($variable) refuses to work...soooooo...the million dollar question is....how can I either load up a variable properly formatted which the array_merge_recursive function will accept?ORhow can I do an array_merge_recursive($array['0'],$array['1],etc,etc,etc, until EOF??)Any takers?? Link to comment https://forums.phpfreaks.com/topic/13165-array_merge_recursive-on-the-same-array/ Share on other sites More sharing options...
Barand Posted June 29, 2006 Share Posted June 29, 2006 [code]$result = array();foreach ($array as $ar) { foreach ($ar as $k=>$val) $result[$k][] = $val;}[/code] Link to comment https://forums.phpfreaks.com/topic/13165-array_merge_recursive-on-the-same-array/#findComment-50703 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.