如何在PHP中的start_time和end_time之间合并两个数组

时间:2017-02-01 10:28:41

标签: php mysql date calendar

我有一个阵列(15分钟):

One
09:00 09:15
09:15 09:30
09:30 09:45
09:45 10:00
10:00 10:15
10:15 10:30
10:30 10:45
10:45 11:00
...

另一个与我的日历:

Two
09:00 10:00 - Calendar 1 (60min)
10:00 10:15 - Calendar 2 (15min)
11:00 11:30 - Calendar 3 (30min)

我需要像这样结合:

Result
09:00 10:00 - Calendar 1
10:00 10:15 - Calendar 2
10:15 10:30
10:30 10:45
10:45 11:00
11:00 11:30 - Calendar 3

感谢您的帮助!

我试着这个:

foreach ($one as $d1) {
    echo $d1['time'];
        foreach ($two as $d2) {
            if ($d1['time'] == $d2['time']) {
            echo 'Ok';
        }
    }
}

这个: $ result = array_merge($ one,$ two); 但它的回归:

09:00 09:15
09:15 09:30
09:30 09:45
09:45 10:00
10:00 10:15
10:15 10:30
10:30 10:45
10:45 11:00
09:00 10:00 - Calendar 1 (60min)
10:00 10:15 - Calendar 2 (15min)
11:00 11:30 - Calendar 3 (30min)

原始阵列

Array 1 (15min)
(
    [0] => Array
        (
            [start_time] => 09:00
            [end_time] => 09:15
        )

    [1] => Array
        (
            [start_time] => 09:15
            [end_time] => 09:30
        )

    [2] => Array
        (
            [start_time] => 09:30
            [end_time] => 09:45
        )

    [3] => Array
        (
            [start_time] => 09:45
            [end_time] => 10:00
        )
    [4] => Array
        (
            [start_time] => 10:00
            [end_time] => 10:15
        )
)


Array 2 (my calendar)
(
    [0] => Array
        (
            [start_time] => 09:00
            [end_time] => 09:30
        )

    [1] => Array
        (
            [start_time] => 09:30
            [end_time] => 09:45
        )
)


Array 3 (Result)
(
    [0] => Array
        (
            [start_time] => 09:00
            [end_time] => 09:30
        )

    [1] => Array
        (
            [start_time] => 09:30
            [end_time] => 09:45
        )
    [2] => Array
        (
            [start_time] => 09:45
            [end_time] => 10:00
        )
    [3] => Array
        (
            [start_time] => 10:00
            [end_time] => 10:15
        )
)

示例:数组3 [0]已合并!

0 个答案:

没有答案