php - Covert multi dimensions array into key values -
sorry wrong described got that.
array ( [0] => hello[30815][183] [1] => hello[30815][291][28280] [2] => hello[30815][291][28280][custom_math] [3] => hello[30815][472][28273][comment] )
after add loop
for($i=0; $i<=count($cfn);$i++) { echo $cfn[$i] ; echo '<br>'; echo $cfv[$i]; echo '<br>'; }
i got type of array
hello[30815][183] => 28275 hello[30815][291][28280] => hello[30815][291][28280][custom_math] => noce hello[30815][472][28273][comment] =>
i want convert
[hello] => array ( [183] => 28275 [291] => array ( [28280] => ) [291] => array ( [28280] => array ( [custom_math] => noce ) ) [472] => array ( [28273] => array ( [comment] => ) ) )
how in php. array length not fixed.30815 id common in all. how resolve issue.
$data //array processing data $productvalue // array values $final = array(); $i=0; foreach ($data $value) { $firststrips = explode("[", $value); $process = array(); foreach($firststrips $key => $firststrip){ if($key==0 || $key==1 ){ continue; } $firststrip = str_replace("]", "", $firststrip); $process[] =(string)$firststrip; } $testarray = convert($process, $productvalue[$i]); $final= array_merge_recursive($testarray,$final); $i++; } function convert($final='', $datavalue) { $out = array(); $cur = &$out; foreach ($final $value) { $cur[$value." "] = array(); (string)$cur = &$cur[$value." "]; $i++; } $cur = $datavalue; return $out; } print_r($final);
Comments
Post a Comment