Nike Yulistia Angreni Nike Yulistia Angreni - 4 months ago 11
PHP Question

How To Change Specific Array Name In PHP

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?

Answer

You could use the union operator and then unset index 0:

$array = [ 'menu_id' => $array[0] ] + $array;
unset($array[0]);