1

i have an array like this

<?php

Array (
        [0] => Array (
                        ['a'] =>'David'
                        ['b'] => 'Paul'
                        [0] => 'Tom'
                     )
        [1] => Array (
                        ['a'] =>'Andrea'
                        ['b'] => 'Chris'
                        [0] => 'Mark'
                     )
)
?>

i have to change the '0' key with a 'c'. how can i do it ?

Salmen Bejaoui
  • 865
  • 1
  • 8
  • 22
  • 1
    Searching first is a good habit. http://stackoverflow.com/questions/13233405/change-key-in-associative-array-in-php – Nabin Kunwar Apr 22 '14 at 06:15
  • possible duplicate of [In PHP, how do you change the key of an array element?](http://stackoverflow.com/questions/240660/in-php-how-do-you-change-the-key-of-an-array-element) – Havelock Apr 22 '14 at 06:44

1 Answers1

0

First copy the contents by simply setting $array['c'] to $array[0] and then remove $array[0]:

$array['c'] = $array[0];
unset($array[0]);
h2ooooooo
  • 39,111
  • 8
  • 68
  • 102