array fetched somewhere else:
Array
(
[0] => Array
(
[id] => 600000
[name] => test1
)
[1] => Array
(
[id] => 600300
[name] => test2
)
[2] => Array
(
[id] => 600600
[name] => test3
)
)
php:
$leftnav = array("root_id" => 0, "sub_id" => 0, "subsub_id" => 0, "subsubsub_id" => 0);
if (isset($category_data[0]['id']))
$leftnav['root_id'] = $category_data[0]['id'];
if (isset($category_data[1]['id']))
$leftnav['sub_id'] = $category_data[1]['id'];
if (isset($category_data[2]['id']))
$leftnav['subsub_id'] = $category_data[2]['id'];
if (isset($category_data[3]['id']))
$leftnav['subsubsub_id'] = $category_data[3]['id'];
Can the php code be done in a more pretty way? I have tried with array_map but all required keys in $leftnav will not be set.
1 Answer