如何重命名数组?

时间:2015-10-21 09:24:08

标签: php arrays

我有这样的数组:

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

我想将父母的名字改为:

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

怎么可能?

2 个答案:

答案 0 :(得分:2)

这样的事情是可能的:

<?php
//keep it in the same variable
$array['searchResult'] = $array[0];
unset($array[0]);

//create a new variable
$new_array = array('searchResult'=>$array[0]);
?>

答案 1 :(得分:1)

这就是我想要的!

 $searchRs['searchRs'] = $resultArr->d;
 unset($resultArr->d);
 return $searchRs;