converting json branched array to php object -
in below code, want display get_data
using echo
not able decode/display branched array. so, question how convert branched array php object.
json response :
{"status":1,"msg":"fetched succesfully","user_data":{"d91c2d21af80002a3dd6ffc76f62bb9f89b6e0ba":{"name":"pratyush","user_year":"2013","get_data":"d91c2d21af80002a3dd6ffc76f62bb9f89b6e0ba","is_active":1,"data_no":"ghjgjj2xxxxxxoioo7","user_bin":"77","is_exp":"n"}}}
php code :(after using curl)
$response = json_decode($o,true); $status=$response["status"]; $msg=$response["msg"]; $user_data=$response["user_data"][0]["get_data"];
result:
echo $status;//(working) echo "<br>"; echo $msg;//(working) echo "<br>"; echo $user_data;//(not working)
echo user_data
not working.
so want value of get_data
. if d91c2d21af80002a3dd6ffc76f62bb9f89b6e0ba
not known, try way.
$user_data_arr=$response["user_data"]; foreach($user_data_arr $user_data_obj) { echo $user_data_obj['get_data'];// here desired value }
using foreach
loop, not have find index , can values easily.
full code
$response = json_decode($o,true); $status=$response["status"]; $msg=$response["msg"]; $user_data=""; $user_data_arr=$response["user_data"]; foreach($user_data_arr $user_data_obj) { $user_data = $user_data_obj['get_data'];// here desired value } echo $status; echo "<br>"; echo $msg; echo "<br>"; echo $user_data;//will work
Comments
Post a Comment