Guest User

Untitled

a guest
Apr 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.67 KB | None | 0 0
  1. <?
  2.     $array[0] = 'aap';
  3.     $array[1] = 'noot';
  4.     $array[3] = 'mies';
  5.     $array[7] = 'wim';
  6.     $array[8] = 'zus';
  7.     $array[9] = 'jet';
  8.     print_r($array);    // print the array
  9.     echo '<br />';
  10.     $size = count($array);  // 6 elements in array
  11.     $r = 0; // read position
  12.     $i = 0; // insert position
  13.     while($i < $size){
  14.         if(isset($array[$r])){  // if there is an element at read position
  15.             $temp = $array[$r]; // read the value into a temp variable
  16.             unset($array[$r]);  // unset (remove from array) the read value
  17.             $array[$i] = $temp; // place it into the array at insert position
  18.             $i++;   // increase inster position
  19.         }
  20.         $r++;   // increase read position
  21.     }
  22.     print_r($array);
  23. ?>
Add Comment
Please, Sign In to add comment