<?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);
You have javascript disabled. You will not be able to edit any code.