3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = 'tacocat'; $code = ''; var_dump((function() { return 1; })()); for ($i = 0; isset($input[$i]); $i++) { $code .= $code ? '.' : ''; $code .= sprintf('(function($str, $pos) { $length = (function($str) { for ($l = 0; isset($str[$l]); $l++) {} return $l - 1; })($str); return $str[$length - $pos]; })(%s, %u)', var_export($input, true), $i); $code .= "\n"; //$code .= sprintf('$input[ - %u]', $i); } //for ($i = strlen($input) - 1; $i >= 0; $i--) { // $code .= ($code ? '.' : '') . sprintf('$input[%s]', $i); //} $code = sprintf('return %s;', $code); var_dump($code); var_dump(eval($code));

preferences:
46.36 ms | 402 KiB | 5 Q