Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

php counter

<?php
//counter while loop
$counter;
while($counter < 10){
	$counter++;
    echo "The number is: $counter <br>";
}
echo $counter; //returns 10

//counter for loop
$counter = 0;
for ($x = 0; $x <= 10; $x++) {
  echo "The number is: $x <br>";
  $counter = $x;
} 
echo $counter; //returns 10

//counter do while
$counter = 1;
do {
  echo "The number is: $counter <br>";
  $counter++;
} while ($counter <= 10);
echo $counter; //returns 10

//counter foreach
$colors = array("red", "green", "blue", "yellow"); 
$counter;
foreach ($colors as $value) {
  echo "$value <br>";
  $counter++;
}
echo count($cars); //returns 4
echo $counter; //returns 4
?>
 
PREVIOUS NEXT
Tagged: #php #counter
ADD COMMENT
Topic
Name
7+7 =