Advertisement
akhyrul

Fill Gap

Sep 21st, 2012
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.59 KB | None | 0 0
  1. <?php
  2. $ar = array(16,17,19,19,20);
  3. $action = false;
  4. $new = array();
  5. $temp = array();
  6.  
  7. foreach ($ar as $key => $val)
  8. {
  9.     if($key == 0 OR $ar[$key-1] == $val)
  10.     {
  11.         // if it's first value,
  12.         // or current value is same as previous,
  13.         // just add it as is
  14.         $new[] = $val;
  15.     }
  16.     else{
  17.         // else,
  18.         // add all missing value including current one
  19.         // to $new array
  20.         for($x = $ar[$key - 1] + 1; $x <= $val; $x++)
  21.         {
  22.             $new[] = $x;
  23.         }
  24.     }
  25. }
  26. echo '<pre>';    
  27. print_r ( $new );
  28. echo '</pre>';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement