Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * for loop (Best)
- * @param $i declaration
- * @param loop stop condition
- * @param $i modification per cycle
- */
- for($i = 0; $i <= 10; $i++){
- echo $i . PHP_EOL;
- }
- /**
- * @return
- * 0
- * 1
- * 2
- * 3
- * 4
- * 5
- * 6
- * 7
- * 8
- * 9
- * 10
- */
- /**
- * while loop (with for() its 90% useless)
- * @param loop stop condition
- */
- $u = 0;
- while ($u <= 10){
- echo $u . PHP_EOL;
- $u++;
- }
- /**
- * @return
- * 0
- * 1
- * 2
- * 3
- * 4
- * 5
- * 6
- * 7
- * 8
- * 9
- * 10
- */
- /**
- * do ... while loop (for heal useless while() with a special property)
- * Special property: its do{} part run once if condition is false
- */
- $v = 8;
- do{
- echo $v . PHP_EOL;
- $v++;
- }while($v < 7);
- /**
- * foreach loop (array loop function)
- * @param an array
- * loop stops when no any value in array is left
- * each value in array($x) first it save as a variable($y)
- * then cycle start after cycle end next value replaces in $y
- */
- $x = array(
- 1,
- 2,
- 3,
- 4,
- 5,
- "Hello",
- "World"
- );
- foreach($x as $y){
- echo $y . PHP_EOL;
- }
- ?>
Add Comment
Please, Sign In to add comment