Networking, Programming and Graphics - Tutorials
ONLINEHOWTO.net Tutorials Category

How to use PHP while operator

Type: Code Networking, Programming and Graphics - Tutorials
Networking, Programming and Graphics - Tutorials
Level: Beginner Networking, Programming and Graphics - Tutorials 
Networking, Programming and Graphics - Tutorials
Date: 2007-Apr-11
Networking, Programming and Graphics - Tutorials
Visited: 5422 times
Networking, Programming and Graphics - Tutorials
Rating: Networking, Programming and Graphics - Tutorials
Networking, Programming and Graphics - Tutorials
Published: Ivory Morhuld

This tutorial will show you how to use PHP while operator

while loops are the simplest type of loop in PHP. They behave just like their C counterparts.

Next example will show you simple code for printing the digits from 10 to 1.
<?php
$k
=10;
while(
$k!=0) {
    echo 
"$k\n";
    
$k--;
}
?>
The result from above PHP script will be:
10
9
8
7
6
5
4
3
2
1
Also while can be used for listing arrays:
<?php
$array
=array("One""Two"3"Apple");
while(list(
$key,$value)=each($array)) {
    echo 
"$key : $value\n";
}
?>
The result from above PHP script will be:
0 : One
1 : Two
2 : 3
3 : Apple
Rate this tutorial:                    
Post Comment

Need a specific tutorial? Do not hesitate and submit a request!
Your e-mail: