arrays - How to get specific keys from a json file with php -


so have json file

[     {         "var1": "6",         "var2": "13",         "var3": "17"     },     {         "var1": "9",         "var2": "11",         "var3": "6"     } ] 

how can values of var2 13 , 11?

use json_decode()

$json = '[{    "var1": "6",    "var2": "13",    "var3": "17"},{    "var1": "9",    "var2": "11",    "var3": "6"}];' $array = json_decode ($json, true); $values = []; foreach ($array $ar) {     $values[] = $ar['var2']; } var_dump($values); 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -