Skip to content
Advertisement

how can I get the key and value from a multidimensional json response using php

Below is my code used to Get data from a REST API to retrieve States .The results contain the State code and State Name to be passed into a select option form with State code as Key and State name as value . My challenge is , i am unable to know the right way to access the data after using json decode

JavaScript

Advertisement

Answer

Based on result

JavaScript

After json_decode(), your $result will be this:

JavaScript

You can simplify it removing the key “States” and holding only its values:

JavaScript

Now you can iterate $result to see the results, for example:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement