3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class AHeap extends SplHeap { public function __construct($i) { foreach ($i as $obj) { $this->insert($obj); } } } class KeySort extends AHeap { public function compare($val1, $val2) { if ($val1->key == $val2->key) return 0; if ($val1->key > $val2->key){ return -1; } else { return 1; } } } class ValueSort extends AHeap { public function compare($val1, $val2) { if ($val1->value == $val2->value) return 0; if ($val1->value < $val2->value){ return -1; } else { return 1; } } } $array = array( (object) array('key' => 0, 'value' => 'z'), (object) array('key' => 1, 'value' => 'a'), (object) array('key' => 2, 'value' => 'y'), (object) array('key' => 3, 'value' => 'b'), ); $heap = new ValueSort($array); foreach ($heap as $val) { echo $val->key . ' - ' . $val->value . PHP_EOL; }
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Return type of KeySort::compare($val1, $val2) 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/EPva0 on line 15 Deprecated: Return type of ValueSort::compare($val1, $val2) 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/EPva0 on line 31 0 - z 2 - y 3 - b 1 - a

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