Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $ar = array(16,17,19,19,20);
- $action = false;
- $new = array();
- $temp = array();
- foreach ($ar as $key => $val)
- {
- if($key == 0 OR $ar[$key-1] == $val)
- {
- // if it's first value,
- // or current value is same as previous,
- // just add it as is
- $new[] = $val;
- }
- else{
- // else,
- // add all missing value including current one
- // to $new array
- for($x = $ar[$key - 1] + 1; $x <= $val; $x++)
- {
- $new[] = $x;
- }
- }
- }
- echo '<pre>';
- print_r ( $new );
- echo '</pre>';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement