3v4l.org

run code in 300+ PHP versions simultaneously
<?php $text = <<<TEXT The answer was within her reach. It was hidden in a box and now that box sat directly in front of her. She'd spent years searching for it and could hardly believe she'd finally managed to find it. She turned the key to unlock the box and then gently lifted the top. She held her breath in anticipation of finally knowing the answer she had spent so much of her time in search of. As the lid came off she could see that the box was empty. TEXT; $offsets = array_keys(str_word_count($text, 2)); $totalPerGroup = intdiv(count($offsets), 10); $chunks = array_chunk($offsets, $totalPerGroup); $starts = array_column($chunks, 0); var_export( array_map( fn($start, $end) => substr($text, $start, $end ? $end - $start : $end), $starts, array_slice($starts, 1) + [null] ) );
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
array ( 0 => 'The answer was within her reach. It was ', 1 => 'hidden in a box and now that box ', 2 => 'sat directly in front of her. She\'d spent ', 3 => 'years searching for it and could hardly believe ', 4 => 'she\'d finally managed to find it. She turned ', 5 => 'the key to unlock the box and then ', 6 => 'gently lifted the top. She held her breath ', 7 => 'in anticipation of finally knowing the answer she ', 8 => 'had spent so much of her time in ', 9 => 'search of. As the lid came off she ', 10 => 'could see that the box was empty.', )

preferences:
75.38 ms | 408 KiB | 5 Q