...

View Full Version : Need help with loop



qazs
12-23-2006, 04:55 PM
Hi,
I have this array:


array('a'=>array('a1','a2'), 'a1'=>array('a1.1','a1.2','a1.3'), 'a1.2'=>array('a1.2.1'));


and I wish to do a replacement of values so it becomes this:



array('a'=>array(array('a1.1',array('a1.2.1'),'a1.3'),'a2'));


Have been trying and trying but I still can't figure out....
Any help is greatly appreciated.

dumpfi
12-23-2006, 05:40 PM
function recRepl($array)
{
_recRepl($array, $array);
return $array;
}
function _recRepl(&$array, &$values)
{
foreach($array as &$value)
{
if(!is_array($value) && isset($values[$value]))
{
$vTemp = $value;
$value = $values[$value];
unset($values[$vTemp]);
}
if(is_array($value))
{
_recRepl($value, $values);
}
}
}

$x = array('a'=>array('a1','a2'), 'a1'=>array('a1.1','a1.2','a1.3'), 'a1.2'=>array('a1.2.1'));
print_r(recRepl($x));
dumpfi



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum