Reputation: 472
Hi I have this json
code
{"points":[ {"10":"10"}, {"1":"1"} ]}
and this is my php
code
$pointsfirst = $row['points'];
$points = json_decode($pointsfirst,true);
$getit = $points['points'][1]['10'];
echo $getit;
$row['points']
is from my database where I have stored the json
and I keep getting this error
Notice: Undefined offset: 10 in /Applications/MAMP/htdocs/projectg/getpointsapi.php on line 46
what am I doing wrong ??
Upvotes: 0
Views: 61
Reputation: 1568
Right way is:
$getit = $points['points'][0][10];
echo $getit;
Upvotes: 2
Reputation: 5155
Arrays in PHP start with offset 0, not 1. This means you should probably use $getit = $points['points'][0]['10'];
instead.
Upvotes: 0
Reputation: 34
Try $getit = $points['points']['1']['10'];
with the quotas! instead...
Upvotes: 0