0

My requirement is to show the list of dates in the array and the time available in that particular date.

I got set all the logic but struggling in one place, please look down about the issue.

I have an array Like below, what I need is to change the 'booked_from_time' to 'from_time' dynamically which ever I want.

How can I achieve this, Please help me to achieve the solution for it.

<!-- Array response -->

[2016-11-25] => Array
    (
        [0] => Array
            (
                [from_time] => 00:00:00
                [to_time] => 23:59:59
            )

    )

[2016-11-26] => Array
    (
        [0] => Array
            (
                [booked_from_time] => 2016-11-26 00:00:00
                [booked_to_time] => 2016-11-26 16:00:00
            )

        [1] => Array
            (
                [booked_from_time] => 2016-11-26 16:00:00
                [booked_to_time] => 2016-11-26 19:20:00
            )

        [2] => Array
            (
                [from_time] => 00:00:00
                [to_time] => 23:59:59
            )

    )

[2016-11-27] => Array
    (
        [0] => Array
            (
                [from_time] => 00:00:00
                [to_time] => 23:59:59
            )

    )
//My Php Code
function multipleBookingsInADay($tempList){
    foreach($tempList as $key => $dataValue){
        $previousFromDate;
        foreach($dataValue as $keyOne => $innerData){

            if(isset($innerData['booked_from_time'])){
                $tempStartTime = date('Y-m-d H:i:s',strtotime($key . " 00:00:00"));
                $tempFromTime = date('Y-m-d H:i:s',strtotime($key . " " . $innerData['booked_from_time']));
                if(empty($previousFromDate)){
                    $previousFromDate = date('Y-m-d H:i:s',strtotime($key . " 00:00:00"));
                }
                $tempList[$key][$keyOne]['booked_from_time'] = $previousFromDate;
                $tempList[$key][$keyOne]['booked_to_time'] = $tempFromTime;
                $previousFromDate = $tempFromTime;
                continue;
            }
            break;
        }
    }
    print_r($tempList);
}

Thanks in Advance.

Bethan
  • 971
  • 8
  • 23

1 Answers1

1

I have fixed my issue with the help of below link.

Replace array keys

Thank You.

Community
  • 1
  • 1
Bethan
  • 971
  • 8
  • 23