Please take a look at the following array..
Array
(
[0] => Array
(
[fee_id] => 15
[fee_amount] => 308.5
[year] => 2009
)
[1] => Array
(
[fee_id] => 14
[fee_amount] => 308.5
[year] => 2009
)
)
I Need output like this,
Array
(
[rfp] => Array
(
[fee_id] => 15
[fee_amount] => 308.5
[year] => 2009
)
[user] => Array
(
[fee_id] => 14
[fee_amount] => 308.5
[year] => 2009
)
)
Is there any possibilities to do that..? I read this PHP rename array keys in multidimensional array
But it explains about the renaming of array keys, But I need this to implement in my live application.
Please help me..
try this code
<?php
$arr[0]['fee_id']=12;
$arr[0]['fee_amount']=308.5;
$arr[0]['year']=2009;
$arr[1]['fee_id']=14;
$arr[1]['fee_amount']=308.5;
$arr[1]['year']=2009;
echo "<pre>";
print_r($arr);
echo "</pre>";
$arr2['rfp']=$arr[0];
$arr2['user']=$arr[1];
echo "<pre>";
print_r($arr2);
echo "</pre>";
?>
Just build a new array with the data:
$newArray=[
'rfp'=>$oldArray[0],
'user'=>$oldArray[1]
];
if you really need to, you can then overwrite the old variable to hold the new array:
$oldArray = $newArray;
This will be as easy as screwing in the imaginary lightbulb.
$array['key_name_you_want'] = $array[0];
unset($array[0]);
This will set all $array[0]
values to $array['key_name_you_want']
and then unset $array[0]
so it will no longer be in $array
.