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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -