php - Checking first level of JSON array -
i have json object follows:
$data = [{"articles": {"id": 5, "name": "bike"},{"id": 6, "name": "car"}}
so, need know kind of info coming client, in case "articles". how can check first level of json object php?
$data = json_decode(' { "articles": [ {"id": 5, "name": "bike"}, {"id": 6, "name": "car"} ] }'); $keys = array_keys((array)$data); echo $keys[0]; //displays: articles
here data valid json (your code invalid). typecasted $data
array array_keys()
not complain passing object.
Comments
Post a Comment