Search code examples
phpfor-loopparse-error

Php Parse Error "For-Loop"


is it possible to do this?
here is my code and error:

for ($i=1; ; $i {
  if (is_numeric($row[$i])) { //Error Line
    $c .= ",".$row[$i];
  } else {
    $c .=",'".$row[$i]."'";
  }
}
$c.=")";

Parse error: syntax error, unexpected T_IF in C:\inetpub\wwwroot.....

for ($i=1; ; $i) {
  if (is_numeric($row[$i])) {
    $c .= ",".$row[$i];
  } else {
    $c .=",'".$row[$i]."'"; // Error Line
  }
}
//$c.=")";

Fatal error: Allowed memory size of 12582912 bytes exhausted

I've Tried Everything I'd Appreciate If You Could Help.. Thanks..


Solution

  • Look at the manual for the for construct. You miss the second expression, used for terminating the loop. Also probably an incrementor.

    What you probably ought to use is:

    for ($i=1; isset($row[$i]); $i++) {
    //              ^^           ^^ 
    //           condition     counter
    

    Usually arrays in PHP start with index 0 and not 1. But we don't know the rest of your code, so.