Change key in Array in php

3

How can I change this array in php

Array ( [respuestas] => Array ( [0] => Array ( [estatus] => ok [mensaje] => Mensaje enviado [referencia] => 2017071908074881946 [numcelular] => 7717477878 ) ) )

a

Array ( [data] => Array ( [0] => Array ( [estatus] => ok [mensaje] => Mensaje enviado [referencia] => 2017071908074881946 [numcelular] => 7717477878 ) ) ) 

I just want to change the name to then create a json and pass it to a DataTable

    
asked by Pyter 20.07.2017 в 03:31
source

1 answer

2

You can add the new "key" with a copy of the data and then delete the previous one. Assume that it is called $ myArray:

$myArray['data'] = $myArray['respuestas'];

unset($myArray['respuestas']);
    
answered by 20.07.2017 / 03:43
source