3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* 1 / \ 2 3 / \ \ 4 5 6 \ 7 */ $a = ['d'=>1, 'l'=>&$b, 'r'=>&$c]; $b = ['d'=>2, 'l'=>&$d, 'r'=>&$e]; $c = ['d'=>3, 'l'=>null, 'r'=>&$f]; $d = ['d'=>4, 'l'=>null, 'r'=>&$g]; $e = ['d'=>5, 'l'=>null, 'r'=>null]; $f = ['d'=>6, 'l'=>null, 'r'=>null]; $g = ['d'=>7, 'l'=>null, 'r'=>null]; bfs($a); echo "\n"; dfs($a); echo "\n"; traverse($t); echo "\n"; function bfs($t) { $queue = [$t]; while ($queue) { $node = array_shift($queue); echo $node['d']; if (is_array($node['l'])) { array_push($queue, $node['l']); } if (is_array($node['r'])) { array_push($queue, $node['r']); } } } function dfs($t) { $stack = [$t]; while ($stack) { $node = array_pop($stack); echo $node['d']; if (is_array($node['r'])) { array_push($stack, $node['r']); } if (is_array($node['l'])) { array_push($stack, $node['l']); } } } function traverse($t) { if (isset($t['d'])) { echo $t['d']; } if (is_array($t['l'])) { traverse($t['l']); } if (is_array($t['r'])) { traverse($t['r']); } } $a = [5,1,2,8,3,4,1]; qsort($a); var_dump($a); function qsort(&$arr, $l = 0, $h = null) { if (is_null($h)) $h = count($arr) - 1; if ($l >= $h) return; $v = $arr[$l]; $i = $l; $j = $h; while ($i < $j) { while ($arr[$j] >= $v && $i < $j) { $j--; } while ($arr[$i] <= $v && $i < $j) { $i++; } if ($i == $j) { $arr[$l] = $arr[$i]; $arr[$i] = $v; break; } $tmp = $arr[$i]; $arr[$i] = $arr[$j]; $arr[$j] = $tmp; } qsort($arr, $l, $i - 1); qsort($arr, $i + 1, $h); } var_dump(binsearch($a, 0)); var_dump(binsearch($a, 1)); var_dump(binsearch($a, 6)); var_dump(binsearch($a, 8)); var_dump(binsearch($a, 9)); function binsearch($arr, $val) { $l = 0; $h = count($arr) - 1; while ($l <= $h) { $m = intval(($l + $h) / 2); if ($arr[$m] == $val) { return $m; } if ($arr[$m] < $val) { $l = $m + 1; } else { $h = $m - 1; } } return -1; }
Output for git.master, git.master_jit
1234567 1247536 Warning: Undefined variable $t in /in/oBVq8 on line 23 Warning: Trying to access array offset on value of type null in /in/oBVq8 on line 58 Warning: Trying to access array offset on value of type null in /in/oBVq8 on line 61 array(7) { [0]=> int(1) [1]=> int(1) [2]=> int(2) [3]=> int(3) [4]=> int(4) [5]=> int(5) [6]=> int(8) } int(-1) int(1) int(-1) int(6) int(-1)
Output for rfc.property-hooks
1234567 1247536 Warning: Undefined variable $t in /in/oBVq8 on line 23 Warning: Trying to access array offset on null in /in/oBVq8 on line 58 Warning: Trying to access array offset on null in /in/oBVq8 on line 61 array(7) { [0]=> int(1) [1]=> int(1) [2]=> int(2) [3]=> int(3) [4]=> int(4) [5]=> int(5) [6]=> int(8) } int(-1) int(1) int(-1) int(6) int(-1)

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