3v4l.org

run code in 300+ PHP versions simultaneously
<?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);
Output for 7.1.0, 7.2.29 - 7.2.33, 7.3.16 - 7.3.33, 7.4.3 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.30, 8.2.0 - 8.2.25, 8.3.0 - 8.3.13
array(2) { [1]=> array(2) { [0]=> array(2) { ["id"]=> int(1001) ["children"]=> array(2) { [0]=> array(3) { ["id"]=> int(10011) ["parent_id"]=> int(1001) ["name"]=> string(10) "onbinonbir" } [1]=> array(3) { ["id"]=> int(10012) ["parent_id"]=> int(1001) ["name"]=> string(10) "onbinoniki" } } } [1]=> array(2) { ["id"]=> int(1002) ["children"]=> array(2) { [0]=> array(3) { ["id"]=> int(10021) ["parent_id"]=> int(1002) ["name"]=> string(13) "onbinyirmibir" } [1]=> array(3) { ["id"]=> int(10022) ["parent_id"]=> int(1002) ["name"]=> string(13) "onbinyirmiiki" } } } } [2]=> array(2) { [0]=> array(2) { ["id"]=> int(2001) ["children"]=> array(2) { [0]=> array(3) { ["id"]=> int(20011) ["parent_id"]=> int(2001) ["name"]=> string(13) "yirmibinonbir" } [1]=> array(3) { ["id"]=> int(20012) ["parent_id"]=> int(2001) ["name"]=> string(13) "yirmibinoniki" } } } [1]=> array(2) { ["id"]=> int(2002) ["children"]=> array(2) { [0]=> array(3) { ["id"]=> int(20021) ["parent_id"]=> int(2002) ["name"]=> string(16) "yirmibinyirmibir" } [1]=> array(3) { ["id"]=> int(20022) ["parent_id"]=> int(2002) ["name"]=> string(16) "yirmibinyirmiiki" } } } } }

preferences:
78.6 ms | 413 KiB | 5 Q