php - Echo will not display any value retrieved from json_decode() -


i have extremely simple json object looks following:

var data = {     "id" : 1 } 

i decode in php:

$decoded_data = json_decode(stripslashes($_post['data']));  //this works $id = intval($decoded_data->id); //in debugger equal 1 expected 

i proceed pass $id variable function queries database , returns set of 'sub activities'

$sub_activities = alp_get_all_sub_activities($id);  //this function works expected , returns correct result set 

now have sub activities designated $id, attempt access them using loop:

foreach ($sub_activities $activity) {     echo __("<td><a id='" . $activity->id . "' href='' title='activity'><div style=' border: 3px solid purple; width: 200px; height: 200px; overflow: scroll;'>" . $activity->name . "<br />" . $activity->id . "<br />" . $activity->description) . "</div></a></td>"; } 

my problem is: echo displays nothing when $id set intval($decoded_data->id), when hardcode $id = 1 works expected , shows in browser. i'm not quite sure how approach problem, because debugger telling me when set $id = intval($decoded_data->id); $id equal 1. can arithmetic number , seems behaves integer would, reason echo , print() not display anything.

if has insight i'd appreciate input.

try accessing value this:

$id = $decoded_data->{'id'}; $id = (int)$decoded_data->{'id'}; $id = intval($decoded_data->{'id'}); $id = (int)$decoded_data->id; 

instead of this:

$id = intval($decoded_data->id); 

thinking little more json treating integer boolean? try

var data = {     "id" : "1" } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -