array_column_recursive 发表于 2020-04-27 | 分类于 PHP 本文字数: 1.5k | 阅读时长 ≈ 1 分钟 思考并回答以下问题: 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849function array_column_recursive(array $haystack, $needle) { $found = []; array_walk_recursive($haystack, function($value, $key) use (&$found, $needle) { if ($key == $needle) $found[] = $value; }); return $found;}$records = [ [ 'id' => 2135, 'first_name' => 'John', 'last_name' => 'Doe', 'meta' => [ 'registered_on' => '1/1/2019', 'more_meta' => [ 'registered_on' => 'i am 3 levels deep', ] ] ], [ 'id' => 3245, 'first_name' => 'Sally', 'last_name' => 'Smith', 'meta' => [ 'registered_on' => '6/1/2019' ] ], [ 'id' => 5342, 'first_name' => 'Jane', 'last_name' => 'Jones', 'meta' => [ 'registered_on' => '12/1/2019' ] ], [ 'id' => 5623, 'first_name' => 'Peter', 'last_name' => 'Doe', 'meta' => [ 'registered_on' => '1/1/2020' ] ]];$registeredOnArray = array_column_recursive($records, 'registered_on');var_export($registeredOnArray); 结果: 123456789/*array ( 0 => '1/1/2019', 1 => 'i am 3 levels deep', 2 => '6/1/2019', 3 => '12/1/2019', 4 => '1/1/2020',) */