I have an array like this:
JavaScript
x
[
[
'id' => 13,
'children' => [
['id' => 14, 'parent_id' => 13],
['id' => 15, 'parent_id' => 13],
]
]
]
How can I get all [id] values from this array and store them in a flat array like this:
JavaScript
[13, 14, 15]
Advertisement
Answer
$a
is your original array.
JavaScript
array_merge(array($a['id']),
array_map(function($child) { return $child['id']; }, $a['children']));