从多维数组中的子数组输出数组
Output array from subarray inside multidimensional array
我想从 $array 中的子数组创建一个数组。我已经设法通过组合操作获得了几乎我想要的东西,但最好是一次性完成。
print_r($array)
产出
Array (
[food] => Array ( [taste] => Sweet [color] => Green )
[drink] => Array ( [smell] => Lemon [type] => Still )
[daisy] => Array ( [color] => Pink [travel] => Paris )
[mike] => Array ( [weight] => 150 [car] => Ford )
[hassan] => Array ( [color] => Red [type] => City )
[results] => Array (
[tabular] => Array (
[time] => Array (
[0] => Array ( [name] => Average [value] => 6 )
[1] => Array ( [name] => Poor [value] => 3 )
[2] => Array ( [name] => Excellent [value] => 22 )
[3] => Array ( [name] => Good [value] => 12 )
[4] => Array ( [name] => Average [value] => 8 )
[5] => Array ( [name] => Poor [value] => 0 )
)
)
)
)
我怎样才能得到这个?
Array (
[0] => Array ( [name] => Average [value] => 6 )
[1] => Array ( [name] => Poor [value] => 3 )
[2] => Array ( [name] => Excellent [value] => 22 )
[3] => Array ( [name] => Good [value] => 12 )
[4] => Array ( [name] => Average [value] => 8 )
[5] => Array ( [name] => Poor [value] => 0 )
)
我试过了
$sliced = (array_slice($array,5));
$reduced = array_reduce($sliced, 'array_merge', array());
$output = array_column($reduced,"time");
print_r($output);
给我
Array (
[0] => Array (
[0] => Array ( [name] => Average [value] => 6 )
[1] => Array ( [name] => Poor [value] => 3 )
[2] => Array ( [name] => Excellent [value] => 22 )
[3] => Array ( [name] => Good [value] => 12 )
[4] => Array ( [name] => Average [value] => 8 )
[5] => Array ( [name] => Poor [value] => 0 )
)
)
print_r($array['results']['tabular']['time'])
我想从 $array 中的子数组创建一个数组。我已经设法通过组合操作获得了几乎我想要的东西,但最好是一次性完成。
print_r($array)
产出
Array (
[food] => Array ( [taste] => Sweet [color] => Green )
[drink] => Array ( [smell] => Lemon [type] => Still )
[daisy] => Array ( [color] => Pink [travel] => Paris )
[mike] => Array ( [weight] => 150 [car] => Ford )
[hassan] => Array ( [color] => Red [type] => City )
[results] => Array (
[tabular] => Array (
[time] => Array (
[0] => Array ( [name] => Average [value] => 6 )
[1] => Array ( [name] => Poor [value] => 3 )
[2] => Array ( [name] => Excellent [value] => 22 )
[3] => Array ( [name] => Good [value] => 12 )
[4] => Array ( [name] => Average [value] => 8 )
[5] => Array ( [name] => Poor [value] => 0 )
)
)
)
)
我怎样才能得到这个?
Array (
[0] => Array ( [name] => Average [value] => 6 )
[1] => Array ( [name] => Poor [value] => 3 )
[2] => Array ( [name] => Excellent [value] => 22 )
[3] => Array ( [name] => Good [value] => 12 )
[4] => Array ( [name] => Average [value] => 8 )
[5] => Array ( [name] => Poor [value] => 0 )
)
我试过了
$sliced = (array_slice($array,5));
$reduced = array_reduce($sliced, 'array_merge', array());
$output = array_column($reduced,"time");
print_r($output);
给我
Array (
[0] => Array (
[0] => Array ( [name] => Average [value] => 6 )
[1] => Array ( [name] => Poor [value] => 3 )
[2] => Array ( [name] => Excellent [value] => 22 )
[3] => Array ( [name] => Good [value] => 12 )
[4] => Array ( [name] => Average [value] => 8 )
[5] => Array ( [name] => Poor [value] => 0 )
)
)
print_r($array['results']['tabular']['time'])