Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.52 KB | None | 0 0
  1. function for_Each($array){    //Creates function for_Each that takes $array as param.
  2.     if ( count($array) === 0 )    //Error if $array is empty.
  3.     {
  4.         throw new Exception('MOM, this one is empty already!',2);
  5.     }
  6.  
  7.     for ( $i = 0; $i < count($array); $i++ )    //Loop 'for' created to go through $array with $i while $i < count($array).
  8.     {
  9.         echo $i . ':' . $array[$i] . PHP_EOL;    //Displays $i (the array's index), then ':', then $array[$i] (the value corresponding to the index of $array)
  10.     }
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement