fork(2) download
  1. <?php
  2.  
  3.  
  4. $input = "[['name' => 'id'], ['type' => 'INT(12)'], ['null' => true], ['prim' => true]], [['name' => 'test'], ['type' => 'VARCHAR(15)'], ['null' => false], ['prim' => true]]";
  5. $raw = '['.
  6. preg_replace(array("/\[([^[{])/","/([^}])\]/"),array("{ $1","$1 }"),
  7. str_replace(array("=>","'"),array(":",'"'),$input)
  8. ).
  9. ']';
  10.  
  11. $output = json_decode(
  12. $raw,
  13. true
  14. );
  15.  
  16. print_r( $raw);
  17. print_r($output);
  18.  
Success #stdin #stdout 0.01s 52488KB
stdin
Standard input is empty
stdout
[[{ "name" : "id" }, { "type" : "INT(12)" }, { "null" : true }, { "prim" : true }], [{ "name" : "test" }, { "type" : "VARCHAR(15)" }, { "null" : false }, { "prim" : true }]]Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [name] => id
                )

            [1] => Array
                (
                    [type] => INT(12)
                )

            [2] => Array
                (
                    [null] => 1
                )

            [3] => Array
                (
                    [prim] => 1
                )

        )

    [1] => Array
        (
            [0] => Array
                (
                    [name] => test
                )

            [1] => Array
                (
                    [type] => VARCHAR(15)
                )

            [2] => Array
                (
                    [null] => 
                )

            [3] => Array
                (
                    [prim] => 1
                )

        )

)