3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ExtendedSPLHeap extends \SPLHeap { protected function compare($a, $b) { if ($a->latitude == $b->latitude) { return 0; } return ($a->latitude < $b->latitude) ? -1 : 1; } } $citiesHeap = new \SplMaxHeap(); $city = new \StdClass; $city->name = "Birmingham"; $city->latitude = 52.4800; $city->longitude = -1.9100; $citiesHeap->insert($city); $city = new \StdClass; $city->name = "Bristol"; $city->latitude = 51.4600; $city->longitude = -2.6000; $citiesHeap->insert($city); echo 'There are ', $citiesHeap->count(), ' cities in the heap', PHP_EOL; echo 'FROM NORTH TO SOUTH', PHP_EOL; $citiesHeap->top(); while ($citiesHeap->valid()) { $city = $citiesHeap->current(); echo sprintf( "%-20s %+3.4f %+3.4f" . PHP_EOL, $city->name, $city->latitude, $city->longitude ); $citiesHeap->next(); } echo $citiesHeap->rewind(); echo 'There are ', $citiesHeap->count(), ' cities in the heap', PHP_EOL;
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Return type of ExtendedSPLHeap::compare($a, $b) should either be compatible with SplHeap::compare(mixed $value1, mixed $value2): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/J4mnl on line 5 There are 2 cities in the heap FROM NORTH TO SOUTH Bristol +51.4600 -2.6000 Birmingham +52.4800 -1.9100 There are 0 cities in the heap

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:
35.55 ms | 402 KiB | 8 Q