3v4l.org

run code in 300+ PHP versions simultaneously
<?php $today = DateTime::createFromFormat('d.m.Y', '17.06.2019'); $dates = [ '17.06.2016', '19.06.2016', '15.06.2016', ]; foreach ($dates as $date) { $mpsAgeT = DateTime::createFromFormat('d.m.Y', $date); $diff = $today->diff($mpsAgeT); $years = $diff->y; if (addOne($diff)) { $years++; } /* 17.06.2019 and 17.06.2016 - should returns me 3 17.06.2019 and 19.06.2016 - should returns me 3 17.06.2019 and 15.06.2016 - should returns me 4 */ print $date . " -> " . $years . "\n"; } function addOne($interval) { $props = ['m', 'd']; foreach ($props as $prop) { if ($interval->{$prop} !== 0) return true; } return false; }
Output for git.master, git.master_jit, rfc.property-hooks
17.06.2016 -> 3 19.06.2016 -> 3 15.06.2016 -> 4

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
28.48 ms | 405 KiB | 5 Q