EsOne Posted January 8, 2010 Share Posted January 8, 2010 I have a script that decodes a json file for information, and I am trying to do a for script for information, but I keep getting an error. I am trying to use the following script <?php $gameCap=0; $glowCt=0; $fishCt=0; for($i in $hay[2][2]{ if($hay[2][2]{i}{'in_env'}==1){ $fishCt++; } if($hay[2][2]{i}{'game_specifics'}){ $gameCap+$hay[2][2]{i}{'game_specifics'}{'rewards'}{0}{'cap'}; $glowCt++; } } ?> And i get: Parse error: syntax error, unexpected T_STRING, expecting ';' Link to comment https://forums.phpfreaks.com/topic/187669-for-not-working/ Share on other sites More sharing options...
The Little Guy Posted January 8, 2010 Share Posted January 8, 2010 first off, a for loop looks like this: for($i = 0; $i < 10; $i++) to loop through an array (which it looks like your trying to do): foreach($arr as $key => $val) Second, you are missing dollar signs for your "i" variables in your if statement $hay[2][2]{i} should be: $hay[2][2]{$i} Link to comment https://forums.phpfreaks.com/topic/187669-for-not-working/#findComment-990761 Share on other sites More sharing options...
EsOne Posted January 8, 2010 Author Share Posted January 8, 2010 Thanks for the reply. I think I am starting to understand. However, i is actually part of the array (As far as I can understand) I'm actually trying to convert some javascript into PHP. Here is the js: var gameCap=0; var glowCt=0; var fishCt=0; for(var i in json[2][2]){ if(json[2][2][i]['in_env']==1){ fishCt++; if(json[2][2][i]['game_specifics']){ gameCap+=Number(json[2][2][i]['game_specifics']['rewards'][0]['cap']); glowCt++; } } } I'm trying to basically do for each i part of the array, if "in env" is found in the i section ++ to fishCT also if there is a "game specifics" array section to add $gameCap to what is in the "cap" part of the array. Sorry if I sound dumb in the way I explain. I am quite new to PHP Link to comment https://forums.phpfreaks.com/topic/187669-for-not-working/#findComment-990767 Share on other sites More sharing options...
trq Posted January 8, 2010 Share Posted January 8, 2010 I have reported this thread to be moved to Javascript help. Link to comment https://forums.phpfreaks.com/topic/187669-for-not-working/#findComment-990771 Share on other sites More sharing options...
EsOne Posted January 8, 2010 Author Share Posted January 8, 2010 I have reported this thread to be moved to Javascript help. It's a PHP problem. The js works, I just need to know how to syntax the PHP. The JS was more of a outline of what I am wanting the PHP to do. Link to comment https://forums.phpfreaks.com/topic/187669-for-not-working/#findComment-990772 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.