3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $str = "abababas"; $d1 = []; $d2 = []; $l = 0; $r = -1; for ($i = 0, $n = strlen($str); $i < $n; $i++) { $k = ($i > $r ? 1 : min($d1[$l + $r - $i], $r - $i)); while ($i - $k >= 0 && $i + $k < $n && $str[$i - $k] == $str[$i + $k]) { $k++; } $d1[$i] = $k; if ($i + $k - 1 > $r) { $l = $i - $k + 1; $r = $i + $k - 1; } } $l = 0; $r = -1; for ($i = 0; $i < $n; $i++) { $k = ($i > $r ? 0 : min($d2[$l + $r - $i - 1], $r - $i)); while ($i - $k >= 0 && $i + $k + 1 < $n && $str[$i - $k] == $str[$i + $k + 1]) { $k++; } $d2[$i] = $k; if ($i + $k > $r) { $l = $i - $k + 1; $r = $i + $k; } } var_dump($d2);
based on 6OISQ
Output for 5.4.10 - 7.3.0beta1
array(8) { [0]=> int(0) [1]=> int(0) [2]=> int(0) [3]=> int(0) [4]=> int(0) [5]=> int(0) [6]=> int(0) [7]=> int(0) }
Output for 5.3.20 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/Uc3Rv on line 4
Process exited with code 255.