How to get multiple keys in JSON with PHP?

0

How to get data with foreach through JSON of this type:

{
    "12": {
        "0": {
            "9678": {
                "920": {
                    "224": {
                        "657": "José da Silva"
                    }
                }
            }
        },
        "1": {
            "0512": {
                "987/21": {
                    "233": {
                        "652": "Maria Silva"
                    }
                }
            }
        }
    }
}
    
asked by anonymous 16.05.2016 / 20:32

1 answer

0

You can use the PHP "json_decode" native function

$json = json_decode('{"12":{"0":{"9678":{"920":{"224":{"657":"José da Silva"}}}},"1":{"0512":{"987/21":{"233":{"652":"Maria Silva"}}}}}}', true);

foreach ($json as $obj) {
    var_dump($obj);
}

Edit

I added a true parameter to json_encode to return the data in array format and not object.

    
16.05.2016 / 20:40