I have an array like this (stored in the $optDir variable):
Array
(
[0] => Array
(
[id] => 8
[title] => Atasan Pria
[idparent] => 5
)
[1] => Array
(
[id] => 5
[title] => Fashion
[idparent] => 0
)
[2] => Array
(
[id] => 7
[title] => Motor
[idparent] => 0
)
[3] => Array
(
[id] => 6
[title] => Mobil
[idparent] => 0
)
[4] => Array
(
[id] => 9
[title] => Hem
[idparent] => 8
)
)
And i have PHP Codes like this :
function optCatAds($pos=0, $level=0){
global $optDir; $opt = "";
$n = count($optDir);
for($i=0;$i<$n;$i++){
$l = $level*3;
$sign=""; for ($z=0;$z<=$l;$z++){$sign.=" ";}
if($optDir[$i]['idparent']==$pos){
$opt .= '<option value="'.$optDir[$i][id].'">'.$sign.$optDir[$i][title].'</option>';
optCatAds($optDir[$i][id], $level + 1);
}
}
return $opt;
}
When i call the optCatAds function, give output like below:
<option value="5">Fashion</option>
<option value="6">Mobil</option>
<option value="7">Motor</option>
But, I want to made output like below :
<option value="5">Fashion</option>
<option value="8"> Atasan Pria</option>
<option value="9"> Hem</option>
<option value="6">Mobil</option>
<option value="7">Motor</option>
Conditions :
Fashion, Mobil, Motor <-- parent
Fashion have child Atasan Pria
Atasan Pria have child Hem
Can someone help me? Thank to your help.