-2

How can i change an index of an array in php? for example

$myArray = {"x","y","z","w"};

I want to change the index of myArray [2] to myArray ["two"]

levenzer
  • 13
  • 2

1 Answers1

0

You could use unset() to achieve this:

$myArray = ["x","y","z","w"];
$myArray['two'] = $myArray[2];
unset($myArray[2]);
Miroslav Glamuzina
  • 4,472
  • 2
  • 19
  • 33