3v4l.org

run code in 300+ PHP versions simultaneously
<?php $myArray = array( 'a','b','c','title1','d','e','f','title2','g','h','title3','i','title4','j','k' ); foreach ($myArray as $v) { if (strpos($v, 'title') !== 0) { $batch[] = $v; } elseif (!empty($batch)) { $result[] = $batch; $batch = []; } } if (!empty($batch)) { $result[] = $batch; } var_export($result);

This is an error 500

Value for `_results` contains invalid data `array`


preferences:
155.09 ms | 2617 KiB | 12 Q