3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<ul> <?php $values = array(); $values[] = array('example'=>'example1','date'=>'2016-12-25'); $values[] = array('example'=>'example2','date'=>'2016-12-26'); $values[] = array('example'=>'example3','date'=>'2016-12-28'); $values[] = array('example'=>'example4','date'=>'2016-12-30'); $previous = null; foreach($values as $example){ echo $previous; echo "<li>".$example['example']." - ".$example['date']; if ($previous !== null) { $diff = strtotime($example['date'])-strtotime($previous); echo " - ".($diff/(60*60*24)); } $previous = $example['date']; echo "</li>\n"; } ?> </ul>
based on 3H2Kq
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.2.6
<ul> <li>example1 - 2016-12-25</li> 2016-12-25<li>example2 - 2016-12-26 - 1</li> 2016-12-26<li>example3 - 2016-12-28 - 2</li> 2016-12-28<li>example4 - 2016-12-30 - 2</li> </ul>