我想从$ 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 )
)
)
答案 0 :(得分:2)
print_r($array['results']['tabular']['time'])