Advertisement
touhid_xml

Lopping array in PHP

Jul 16th, 2015
500
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3.  
  4. $numbers = array(10,20,30,40);
  5.  
  6. /**
  7.  *
  8.  * Fetch array with for loop
  9.  */
  10. /**for($i=0; $i<4; $i++){
  11.     echo "{$numbers[$i]}<br />\n";
  12. } **/
  13.  
  14.  
  15. /***
  16.  * Fetch array with foreach loop
  17.  * Foreach loop is specially develope for array
  18.  */
  19.  
  20. /**foreach($numbers as $number){
  21. echo $number . "<br />\n";
  22. } **/
  23.  
  24.  
  25. /****
  26.  * Extract $key and $value in foreach loop from array
  27.  */
  28.  
  29. /**foreach($numbers as $key => $value){
  30. echo "Key: {$key}, Value: {$value}<br />\n";
  31. } **/
  32.  
  33.  
  34. /***
  35.  * Fetch array with while loop
  36.  */
  37. /***
  38.  $i = 0;
  39. while($i<4){
  40.     echo "{$numbers[$i]}<br />\n";
  41.     $i++;
  42. }
  43.  *
  44.  * **/
  45. $i = 0;
  46. do{
  47.     echo "{$numbers[$i]}<br />\n";
  48.     $i++;
  49. }while($i<4);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement