I'm trying to create multidimensional array with start_date and end_date values
$array = [];
$i = 0;
while ($row = mysqli_fetch_assoc($result)) {
$array[$i]['start_date'] = $row['current_status_start_time'];
$array[$i]['end_date'] = '';
$i++;
}
print_r($array);
This returns me array like this:
Array (
[0] => Array (
[start_date] => 2013-07-25 11:18:42
[end_date] => )
[1] => Array (
[start_date] => 2013-07-26 05:24:08
[end_date] => )
[2] => Array (
[start_date] => 2013-07-31 17:25:05
[end_date] => )
)
end_date should get next array [start_date] node value:
Array (
[0] => Array (
[start_date] => 2013-07-25 11:18:42
[end_date] => **2013-07-26 05:24:08**)
[1] => Array (
[start_date] => **2013-07-26 05:24:08**
[end_date] => 2013-07-31 17:25:05)
[2] => Array (
[start_date] => 2013-07-31 17:25:05
[end_date] => current_date)
)
As you can see in the last code example, array[0][end_date] should get array[1][start_date] value and so on, the last array end_date should get current time value, because there is end of array.
Should I use second loop to achieve that? or there is alternative and more simple way?