Reputation: 311
I have array :
Array
(
[0] => 166
[role_code] => new role test
)
I want to change [0]
into [menu_id]
. How i can change it on PHP code?
Upvotes: 2
Views: 60
Reputation: 305
You could use the union operator and then unset index 0:
$array = [ 'menu_id' => $array[0] ] + $array;
unset($array[0]);
Upvotes: 4
Reputation: 48
You can just assign the value to a new item and unset the previous one.
$array['menu_id'] = $array[0];
unset($array[0]);
Upvotes: 2