Convert array

How to get this array:

Array
(
    [0] => Array
        (
            [max] => 5
            [year] => 2007
        )

    [1] => Array
        (
            [max] => 6.05
            [year] => 2008
        )

    [2] => Array
        (
            [max] => 7
            [year] => 2009
        )

)

      

In this format:

[year] => [max]

      

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

0


a source to share


3 answers


$result = array();
foreach($array as $v) {
    $result[$v['year']] = $v['max'];
}

      



There you go.

+5


a source


you will need to iterate over the current array and put the data into the new array.



$result = array();
foreach($currenArray as $x) 
{
    $result[$x['year']] = $x['max'];
}

      

+1


a source


Easy way?

$dest = array();
foreach ($src as $k => $v) {
  $dest[$v['year']] = $v['max'];
}

      

+1


a source







All Articles