我如何获得此阵列:
Array
(
[0] => Array
(
[max] => 5
[year] => 2007
)
[1] => Array
(
[max] => 6.05
[year] => 2008
)
[2] => Array
(
[max] => 7
[year] => 2009
)
)
采用以下格式:
[year] => [max]
(对我的无知感到惭愧......其中一天)
答案 0 :(得分:5)
$result = array();
foreach($array as $v) {
$result[$v['year']] = $v['max'];
}
你去。
答案 1 :(得分:1)
您需要遍历当前数组并将数据放入新数组中。
$result = array();
foreach($currenArray as $x)
{
$result[$x['year']] = $x['max'];
}
答案 2 :(得分:1)
简单的方法?
$dest = array();
foreach ($src as $k => $v) {
$dest[$v['year']] = $v['max'];
}