Hi I have some simple code here that as far as I can tell should be working but it doesn’t and I am puzzled as to why
//VARIABLES
$rowcount=15;
$colcount=15;
$path= array( array());
$startrow=8;
$startcol=7;
$row=$startrow;
$col=$startcol;
for ($a=0;$a<$rowcount;$a++) {
for ($b=0;$b<$colcount;$b++) {
$path[$a][$b]=0;
}
}
echo"In case one ";
echo"<BR>";
echo " Col= ".$col;
echo " Row= ".$row-1;
echo " Col= ".$col;
echo " Cell= ".$path[$row-1][$col];
echo " Cellx= ".$path[7][7];
if($path[$row-1][$col]=="o") {
echo " F1 = ".$flagOne;
$flagOne="1";
echo " cell equals ==o==";
echo " F1 = ".$flagOne;
} else {
echo " cell not equal ==o==";
}
echo"<BR>";
This is what I get as a output
In case one
Col= 7-1 Col= 7 Cell= 0 Cellx= 0 F1 = 0 cell equals ==o== F1 = 1
what puzzles me is the 7th spot “-1”
I would expect to see “Row= 7” not “-1” since $row=8
I have been programming in java and C and lately just barely touching PHP lately but I have been doing PHP for years, I think this should be working
what am i doing wrong
As another issue
looking at the if statement the value of the array/cell = 0 so I would also expect the evaluation to be false and echo this
cell not equal ==o==
but the condition is evaluating true why is this
my one thought is the way I am setting up the $path variable
I simply want it to be a simple two dimensional array $path[$a][$b] is it setup correctly when I output the array I see what I am expecting an two dimensional array.
Never had to do these much in the past
At first, dont use double-quotes all over the script. There is a special meaning to double and single quotes in PHP, read the manual about this. Second – character “o” is not zero. You can clearly see, that You are trying to match zero against lower-case “o”. Also, integers does not need to be quoted in PHP just as in about every language out there. Check Your font settings to differ one from another. Third – If You are doing both evaluation and concatenation in PHP, You should surround evaluation statement with parentheses, although it is a bad practice. It is better to pre-calculate values and assign them to values before sending them to output or before concatenating them with another values as strings.