fork download
  1. <?php
  2.  
  3. $array = array(
  4. 'American Theater',
  5. '2014-06-04T13:10',
  6. '2014-06-04T15:10',
  7. 'Grand Theater',
  8. '2014-06-04T15:30',
  9. '2014-06-04T19:10'
  10. );
  11.  
  12. $i = 0;
  13.  
  14. foreach ($array as $key => $value) {
  15.  
  16. if (strtotime($value)) {
  17. $index = $i - 1;
  18. $theaters[$i - 1]['showtimes'][] = $value;
  19. }
  20. else {
  21. $theaters[$i]['theater']['name'] = $value;
  22. $i++;
  23. }
  24.  
  25. }
  26.  
  27. print_r($theaters);
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
Array
(
    [0] => Array
        (
            [theater] => Array
                (
                    [name] => American Theater
                )

            [showtimes] => Array
                (
                    [0] => 2014-06-04T13:10
                    [1] => 2014-06-04T15:10
                )

        )

    [1] => Array
        (
            [theater] => Array
                (
                    [name] => Grand Theater
                )

            [showtimes] => Array
                (
                    [0] => 2014-06-04T15:30
                    [1] => 2014-06-04T19:10
                )

        )

)