tags:

views:

70

answers:

3

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]

(ashamed at my ignorance...one of those days)

+1  A: 

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'];
}
Josh Curren
+1  A: 

Simple way?

$dest = array();
foreach ($src as $k => $v) {
  $dest[$v['year']] = $v['max'];
}
cletus
wont work. $k is the Keys that are 0,1,2.
José Leal
You're right. Fixed.
cletus
+5  A: 
$result = array();
foreach($array as $v) {
    $result[$v['year']] = $v['max'];
}

There you go.

José Leal