Transform a JSON string into a non-associative array in PHP

1

Good afternoon,

I would like to convert a string to a non-associative array in PHP, functions like json_encode / json_encode are not working properly.

String:

  

word = '{"world": ["CE", "Supply"], "regional": ["CSC"   RJ / Verticalized "]," Entity entity ": [" G & G "," BSA -   , "Area": null};

I'm trying to get something like:

  

[0 => ["CE", "Supply"], 1 => ["CSC", "Regional"   GGI "," BSA - Graphic "], 2 => [" G & G "," BSA -   Graphic "]]

Thank you in advance for your attention.

    
asked by anonymous 19.10.2016 / 16:08

2 answers

1

Try this:

$resultado = array_values( json_decode( $palavra, true ) );

The second parameter of json_decode () defines whether it returns as object (false) or array associative (true). Once with an array you just have to discard the keys using array_values () ;

    
19.10.2016 / 16:10
0
   <?php


    $data = '{ "mundo":["CE","Supply"], "regional":["CSC","Regional RJ/Verticalizadas"], "entidadeAgrupada":["G&G","BSA - Gráfica"], "unidade":["GGI","BSA - Gráfica"],"area":null }';


    $data1 = json_decode(trim($data), true);

    $data2 = $data1['mundo'];

    echo "<br>"; 
    print_r( $data1); 
    echo "<br>"; 
    echo "<br>";
     echo "<br>"; 
    print_r( $data2);

Result:

Array ([world] => Array ([0] => CE [1] => Supply) [regional] => Array ([0] => CSC [1] => Regional GGI [1] => BG - Graphics) [unit] => Array ([0] => GGI [1] => GGI [1] => > BSA - Graphics) [area] = >)

Array ([0] => CE [1] = > Supply)

    
19.10.2016 / 16:26