user967144
user967144

Reputation: 481

php array - get first row of ETime and next row of STime

Here's my php array with row start and end times

Array
(
    [0] => Array
        (
            [STime] => 09:00:00
            [ETime] => 10:00:00
        )

    [1] => Array
        (
            [STime] => 10:15:00
            [ETime] => 11:15:00
        )

    [2] => Array
        (
            [STime] => 11:30:00
            [ETime] => 12:15:00
        )

)

How can i format my array to get first row of ETime and next row of STime. Result should be an array of

Array ( [0] => Array ( [0] => 10:00:00 [1] => 10:15:00 )

    [1] => Array
        (
          [0] => 11:15:00
            [1] => 11:30:00
        ) 

    [2] => Array
        (
            [0] => 12:15:00
        )

)

Upvotes: 0

Views: 212

Answers (1)

k102
k102

Reputation: 8079

try this:

foreach ($array1 as $key => $value){
  if (isset($array1[$key+1]['STime'])){
    $array2[] = array($value['ETime'],$array1[$key+1]['STime']);
  }
  else{
    $array2[] = array($value['ETime']);
  }
}

Upvotes: 2

Related Questions