Guest User

Untitled

a guest
Jul 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. <?php
  2. /**
  3. * for loop (Best)
  4. * @param $i declaration
  5. * @param loop stop condition
  6. * @param $i modification per cycle
  7. */
  8. for($i = 0; $i <= 10; $i++){
  9. echo $i . PHP_EOL;
  10. }
  11. /**
  12. * @return
  13. * 0
  14. * 1
  15. * 2
  16. * 3
  17. * 4
  18. * 5
  19. * 6
  20. * 7
  21. * 8
  22. * 9
  23. * 10
  24. */
  25. /**
  26. * while loop (with for() its 90% useless)
  27. * @param loop stop condition
  28. */
  29. $u = 0;
  30. while ($u <= 10){
  31. echo $u . PHP_EOL;
  32. $u++;
  33. }
  34. /**
  35. * @return
  36. * 0
  37. * 1
  38. * 2
  39. * 3
  40. * 4
  41. * 5
  42. * 6
  43. * 7
  44. * 8
  45. * 9
  46. * 10
  47. */
  48. /**
  49. * do ... while loop (for heal useless while() with a special property)
  50. * Special property: its do{} part run once if condition is false
  51. */
  52. $v = 8;
  53. do{
  54. echo $v . PHP_EOL;
  55. $v++;
  56. }while($v < 7);
  57. /**
  58. * foreach loop (array loop function)
  59. * @param an array
  60. * loop stops when no any value in array is left
  61. * each value in array($x) first it save as a variable($y)
  62. * then cycle start after cycle end next value replaces in $y
  63. */
  64. $x = array(
  65. 1,
  66. 2,
  67. 3,
  68. 4,
  69. 5,
  70. "Hello",
  71. "World"
  72. );
  73. foreach($x as $y){
  74. echo $y . PHP_EOL;
  75. }
  76. ?>
Add Comment
Please, Sign In to add comment