05-28-2008, 02:01 AM
|
#1 (permalink)
|
|
The Acquainted
Join Date: May 2008
Posts: 175
Thanks: 9
|
Build multi-dimensional array out of a flat array
Hi All,
I am having some issues doing this. I think the only way to accomplish this is to use a recursive function, however I am failing miserably.
Basically, I need to turn a flat array into a multi-dimensional array.
The flat arrays *values* need to become the new *keys* to the multi-dimensional array.
The array I feed to it can have 1 value in it, up to nth high.
Example:
PHP Code:
// Starts out as $array = array(0 => '0', 1 => '15', 2 => '32', 3 => '18');
// Is turned into $array = array('0' => array('15' => array('32' => array('18' => array() ) ) ) );
As I said though, my attempts have failed with all kinds of unknown indexes and the like.
PHP Code:
function recursiveBuildArray($array, &$temp) { if (isset($array['0'])) { $temp[$array['0']] &= array(); $id = $array['0']; unset($array['0']); $this->recursiveBuildArray($array[$id], &$temp); } else { return false; } }
Any help on this one?
|
|
|