[ create a new paste ] login | about

Link: http://codepad.org/8ahi0OOo    [ raw code | output | fork ]

PHP, pasted on May 3:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
error_reporting(~0);

$hours = array(
    0 => 0,
    1 => 1,
    2 => 2,
    3 => 3,
    4 => 3
);

foreach(array_slice(array_reverse(array_keys($hours)), 0, -1) as $i)
    ($hours[$i] === $hours[$i-1]) && $hours[$i] = NULL;

var_dump($hours);


Output:
1
2
3
4
5
6
7
8
9
10
11
12
array(5) {
  [0]=>
  int(0)
  [1]=>
  int(1)
  [2]=>
  int(2)
  [3]=>
  int(3)
  [4]=>
  NULL
}


Create a new paste based on this one


Comments: