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.

2
  • Try array_merge concept. Commented Nov 10, 2016 at 13:38
  • 1
    Please provide your desired result based on the example given above. Commented Nov 10, 2016 at 13:44

1 Answer 1

1

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

Replace array keys

Thank You.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.