With the following code:
$array = array(
'id' => '1',
'parent_id' => '0',
'name' => 'top level',
'children' => array(
'id' => '2',
'parent_id' => '1',
'name' => 'second level',
'children' => array(
'id' => '3',
'parent_id' => '2',
'name' => 'third level'
)
)
);
function generateFlatArray($array){
$output .= '[select id="' . $array['id'] . '" name="' . $array['name'] . '"]';
if(is_array($array['children'])){
generateFlatArray($array['children']);
}
return $output;
}
print_r(generateFlatArray($array));
Why does this output:
[select id="1" name="top level"]
and not what I am expecting, which is:
[select id="1" name="top level"][select id="2" name="second level"][select id="3" name="third level"]
I hate recursion. I hate recursion. I hate recursion. Thanks.