3v4l.org

run code in 300+ PHP versions simultaneously
<?php function hasLoop($head) { $slow = $head; $fast = $head; while ($fast !== null && $fast->next !== null) { $slow = $slow->next; $fast = $fast->next->next; if ($slow === $fast) { return true; } } return false; } // example usage class Node { public $data; public $next; public function __construct($data) { $this->data = $data; $this->next = null; } } $a = new Node(1); $b = new Node(2); $c = new Node(3); $d = new Node(4); $a->next = $b; $b->next = $c; $c->next = $d; var_dump(hasLoop($a)); // false $d->next = $b; var_dump(hasLoop($a)); // true
Output for git.master_jit, git.master, rfc.property-hooks
bool(false) bool(true)

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:
94.94 ms | 405 KiB | 5 Q