Jump to content

For not working...


EsOne

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.