3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $states = json_decode('[[[1,0,1],[1,1,0]],[[1,1],[1,0,1]]]'); $state = 0; $tape = array(1, 1, 1); $zend7lol = substr(phpversion(), 0, 1) == 7 && substr(phpversion(), -5) != '-hhvm'; $tape[] = 0; foreach ($tape as $k => &$v) { if (is_null($state)) { echo "stopping\n"; break; } var_dump($tape); @list ($v, $d, $state) = $states[$state][$v]; var_dump($tape); if ($d) { //var_dump(count($tape), $k); if (count($tape) - $k < 3) { $p = $tape; end($tape); $tape[] = 0; unset($p); } } elseif ($k) { $r = $tape; prev($r); if (!$zend7lol) prev($r); $tape = $r; unset($r); } else { array_unshift($tape, 0); if ($zend7lol) { $lol = $tape; reset($tape); unset($lol); } } } unset($v); var_dump($tape);
based on v74JB
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.2.6
array(4) { [0]=> &int(1) [1]=> int(1) [2]=> int(1) [3]=> int(0) } array(4) { [0]=> &int(1) [1]=> int(1) [2]=> int(1) [3]=> int(0) } array(4) { [0]=> int(1) [1]=> &int(1) [2]=> int(1) [3]=> int(0) } array(4) { [0]=> int(1) [1]=> &int(1) [2]=> int(1) [3]=> int(0) } array(4) { [0]=> int(1) [1]=> int(1) [2]=> &int(1) [3]=> int(0) } array(4) { [0]=> int(1) [1]=> int(1) [2]=> &int(1) [3]=> int(0) } array(5) { [0]=> int(1) [1]=> int(1) [2]=> int(1) [3]=> &int(0) [4]=> int(0) } array(5) { [0]=> int(1) [1]=> int(1) [2]=> int(1) [3]=> &int(1) [4]=> int(0) } array(5) { [0]=> int(1) [1]=> int(1) [2]=> &int(1) [3]=> int(1) [4]=> int(0) } array(5) { [0]=> int(1) [1]=> int(1) [2]=> &int(1) [3]=> int(1) [4]=> int(0) } array(5) { [0]=> int(1) [1]=> &int(1) [2]=> int(1) [3]=> int(1) [4]=> int(0) } array(5) { [0]=> int(1) [1]=> &int(1) [2]=> int(1) [3]=> int(1) [4]=> int(0) } array(5) { [0]=> &int(1) [1]=> int(1) [2]=> int(1) [3]=> int(1) [4]=> int(0) } array(5) { [0]=> &int(1) [1]=> int(1) [2]=> int(1) [3]=> int(1) [4]=> int(0) } array(6) { [0]=> &int(0) [1]=> int(1) [2]=> int(1) [3]=> int(1) [4]=> int(1) [5]=> int(0) } array(6) { [0]=> &int(1) [1]=> int(1) [2]=> int(1) [3]=> int(1) [4]=> int(1) [5]=> int(0) } stopping array(6) { [0]=> int(1) [1]=> int(1) [2]=> int(1) [3]=> int(1) [4]=> int(1) [5]=> int(0) }