如何使用PHP减去时间?

时间:2019-04-24 07:14:27

标签: php datetime

我正在尝试将一个数组减去另一个数组。但这与时间有关。我无法产生预期的输出。我只想从第一个数组中删除第二个数组重叠时隙。

我以以下数组为例

$array1 = [
            0 => [
                'start_hour' => 9,
                'start_minute' => 0,
                'end_hour' => 12,
                'end_minute' => 0
            ],
            1 => [
                'start_hour' => 13,
                'start_minute' => 0,
                'end_hour' => 18,
                'end_minute' => 0
            ]
        ];

 $array2 = [
            'start_hour' => 11,
            'start_minute' => 0,
            'end_hour' => 11,
            'end_minute' => 30
        ];

现在我想从$ array1中减去$ array2。

我的预期输出如下:

 $result = [
            0 => [
                'start_hour' => 9,
                'start_minute' => 0,
                'end_hour' => 11,
                'end_minute' => 0
            ],
            1 => [
                'start_hour' => 11,
                'start_minute' => 30,
                'end_hour' => 12,
                'end_minute' => 0
            ],
            2 => [
                'start_hour' => 13,
                'start_minute' => 0,
                'end_hour' => 18,
                'end_minute' => 0
            ]
        ];

任何解决方案或某种线索将不胜感激。预先感谢。

0 个答案:

没有答案