Reputation: 4976
How do I get this array:
Array
(
[0] => Array
(
[max] => 5
[year] => 2007
)
[1] => Array
(
[max] => 6.05
[year] => 2008
)
[2] => Array
(
[max] => 7
[year] => 2009
)
)
Into this format:
[year] => [max]
Upvotes: 0
Views: 129
Reputation: 625017
Simple way?
$dest = array();
foreach ($src as $k => $v) {
$dest[$v['year']] = $v['max'];
}
Upvotes: 1
Reputation: 10226
you would need to iterate through your current array and put the data into a new array.
$result = array();
foreach($currenArray as $x)
{
$result[$x['year']] = $x['max'];
}
Upvotes: 1
Reputation: 8109
$result = array();
foreach($array as $v) {
$result[$v['year']] = $v['max'];
}
There you go.
Upvotes: 5