This is the var_dump($options)
array (size=4)
0 => string '2' (length=1)
'parent_2_children' =>
array (size=3)
0 => string '22' (length=2)
1 => string '24' (length=2)
2 => string '23' (length=2)
1 => string '3' (length=1)
'parent_3_children' =>
array (size=3)
0 => string '26' (length=2)
1 => string '25' (length=2)
2 => string '27' (length=2)
What I have tried up to now is
if(!is_null($options))
{
foreach($options as $option)
{
if(!array_key_exists('parent_'.$option.'_children',$options))
{
//if position null output an error
}
}
}
Print_r() as requested
Array
(
[0] => 2
[parent_2_children] => Array
(
[0] => 22
[1] => 24
[2] => 23
)
[1] => 3
[parent_3_children] => Array
(
[0] => 26
[1] => 25
[2] => 27
)
)
Your code is correct. An additional check on the nature of the key will reduce the execution, since you have to do the processing only for numeric keys.
To test the code, try the following array :
whose print_r output will be :
)
and, it will output :