duanlujiaji10335 2016-11-10 13:34
浏览 26
已采纳

在PHP中更改现有的数组键值

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.

  • 写回答

1条回答 默认 最新

  • duanguo7021 2016-11-11 07:42
    关注

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

    Replace array keys

    Thank You.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效