3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function getMiddle($text) { $len = strlen($text); $parity = $len % 2; if ($parity === 0) { $middle = sprintf("%s%s", $text[($len/2)-1], $text[$len/2]); var_dump($middle); } else { var_dump(ceil($len/2)); var_dump($text[ceil($len/2)]); $middle = sprintf("%s", intval($text[ceil($len/2)])); var_dump($middle); } // $middle = $parity === 0 ? // sprintf("%s%s", $text[($len/2)-1], $text[$len/2]) : // sprintf("%s", $text[ceil($len/2)]); return $middle; } getMiddle('test'); getMiddle('tests');
based on mm22Z
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.3.0rc3
string(2) "es" float(3) Notice: String offset cast occurred in /in/V7IHs on line 12 string(1) "t" Notice: String offset cast occurred in /in/V7IHs on line 13 string(1) "0"