[Solved] Php foreach loop syntax [closed]


This is not a correct foreach syntax. Use for loop instead.

$a = array("marx","engels","lenin","stalin","mao zedong");
$a_size = count($a);
for($i=0; $i<$a_size; $i++) {
  echo $a[$i];
}

Foreach usage.

$comrades = array("marx","engels","lenin","stalin","mao zedong");
foreach($comrades as $comrade) {
  echo "Comrade ".$comrade;
}

solved Php foreach loop syntax [closed]