PHP rename array keys in multidimensional array

In an array such as the one below, how could I rename "fee_id" to "id"?

Array
(
    [0] => Array
        (
            [fee_id] => 15
            [fee_amount] => 308.5
            [year] => 2009                
        )

    [1] => Array
        (
            [fee_id] => 14
            [fee_amount] => 308.5
            [year] => 2009

        )

)

foreach ( $array as $k=>$v )
{
  $array[$k] ['id'] = $array[$k] ['fee_id'];
  unset($array[$k]['fee_id']);
}

This should work


You could use array_map() to do it.

$myarray = array_map(function($tag) {
    return array(
        'id' => $tag['fee_id'],
        'fee_amount' => $tag['fee_amount'],
        'year' => $tag['year']
    ); }, $myarray);

$arrayNum = count($theArray);

for( $i = 0 ; $i < $arrayNum ; $i++ )
{
    $fee_id_value = $theArray[$i]['fee_id'];
    unset($theArray[$i]['fee_id']);
    $theArray[$i]['id'] = $fee_id_value;
}

This should work.