- var_dump: documentation ( source)
- array_column: documentation ( source)
<?php
$d = [
[
'id' => 1,
'name' => 'bir',
'children' => [
[
'id' => 1001,
'children' => [
[
'id' => 10011,
'parent_id' => 1001,
'name' => 'onbinonbir',
],
[
'id' => 10012,
'parent_id' => 1001,
'name' => 'onbinoniki',
]
]
],
[
'id' => 1002,
'children' => [
[
'id' => 10021,
'parent_id' => 1002,
'name' => 'onbinyirmibir',
],
[
'id' => 10022,
'parent_id' => 1002,
'name' => 'onbinyirmiiki',
]
]
]
]
],
[
'id' => 2,
'name' => 'iki',
'children' => [
[
'id' => 2001,
'children' => [
[
'id' => 20011,
'parent_id' => 2001,
'name' => 'yirmibinonbir',
],
[
'id' => 20012,
'parent_id' => 2001,
'name' => 'yirmibinoniki',
]
]
],
[
'id' => 2002,
'children' => [
[
'id' => 20021,
'parent_id' => 2002,
'name' => 'yirmibinyirmibir',
],
[
'id' => 20022,
'parent_id' => 2002,
'name' => 'yirmibinyirmiiki',
]
]
]
]
]
];
$birinciler = array_column($d, 'id', 'id');
//var_dump($birinciler);
$ikinciler = array_column($d, 'children', 'id');
var_dump($ikinciler);
$ucunculer = array_column($ikinciler, 'children');
//var_dump($ikinciler);