Convert text to PHP array [duplicated]

2

I have a text that has this format:

{
  "id":"1",
  "creado_por":"superadmin",
  "fecha_y_hora_de_creacion":"2018-06-09 11:04:08",
  "auditor_asignado":"Yheferzon",
  "nombre_beneficiario":"CHARLES XAVIER"
}

And I have not been able to turn it into an array to work with, some little hand I thank you for.

    
asked by Mauricio Delgado 27.06.2018 в 19:09
source

1 answer

1

That string is JSON , so if you have that text in a variable, you can use json_decode. The second parameter, TRUE , means that you want an associative array returned. Try this code:

<?php
$text = '{
  "id":"1",
  "creado_por":"superadmin",
  "fecha_y_hora_de_creacion":"2018-06-09 11:04:08",
  "auditor_asignado":"Yheferzon",
  "nombre_beneficiario":"CHARLES XAVIER"
}';

$array = json_decode($text, TRUE);

echo $array['id'];

?>
    
answered by 27.06.2018 / 19:21
source