Главоблъсканица с два масива, грешка в логиката

Ticketa

Registered
Яко съм зациклил :D
Имам два масива като съм се опитал да е "уеднаквя" на максимум двете структури:

Масив 1. представлява данни с всички налични типове стаи за отдаване под наем. (добавил съм параметри: start, end, interval) просто ако се налага да се ползват, ако направим проверката без тях още по-добре, ще ги изтрия)

Масив 2. представлява данни с всички ЗАПАЗЕНИ до този момент стаи.

Трябва да сравня дали стая от масив 1 съществува в масив 2 (сравнение) и ако съществува тогава да игнорирам този запис и да покажа липсващия от масив 1

Опитах чрез array_diff_assoc($array1, $array2); (понеже е многомерен масив, обаче нещо не успях да напасна нещата)
Както и чрез: array_diff(array_column($array1, 'title'), array_column($array2, 'title'))


Масив 1:
Код:
Array
(
    [0] => Array
        (
            [title] => Студио
            [start] => 
            [end] => 
            [interval] => 
        )

    [1] => Array
        (
            [title] => Двойна стая
            [start] => 
            [end] => 
            [interval] => 
        )

    [2] => Array
        (
            [title] => Единична стая
            [start] => 
            [end] => 
            [interval] => 
        )

    [3] => Array
        (
            [title] => Тройна стая
            [start] => 
            [end] => 
            [interval] => 
        )

)


Масив 2:
Код:
Array
(
    [0] => Array
        (
            [title] => Тройна стая
            [start] => DateTime Object
                (
                    [date] => 2021-11-01 00:00:00.000000
                    [timezone_type] => 3
                    [timezone] => UTC
                )

            [end] => DateTime Object
                (
                    [date] => 2021-12-30 00:00:00.000000
                    [timezone_type] => 3
                    [timezone] => UTC
                )

            [interval] => 59
        )

    [1] => Array
        (
            [title] => Двойна стая
            [start] => DateTime Object
                (
                    [date] => 2021-11-12 00:00:00.000000
                    [timezone_type] => 3
                    [timezone] => UTC
                )

            [end] => DateTime Object
                (
                    [date] => 2021-11-28 00:00:00.000000
                    [timezone_type] => 3
                    [timezone] => UTC
                )

            [interval] => 16
        )

    [2] => Array
        (
            [title] => Студио
            [start] => DateTime Object
                (
                    [date] => 2021-11-28 00:00:00.000000
                    [timezone_type] => 3
                    [timezone] => UTC
                )

            [end] => DateTime Object
                (
                    [date] => 2021-11-30 00:00:00.000000
                    [timezone_type] => 3
                    [timezone] => UTC
                )

            [interval] => 2
        )

)
 
uphero каза:
Като не можеш да се оправяш с масиви ги въртиш - това е начина.

Същност имам решение, но не ми е задоволително.
Код:
<?php
$array1 = [
            ['title' => 'asd', 'START' => '2021-11-01', ],
            ['title' => 'test', 'START' => '2021-11-01', ],
            ['title' => 'mega', 'START' => '2021-11-01', ],
        ];
$array2 = [
            ['title' => 'asd', 'START' => '2021-11-01', ],
            ['title' => 'test', 'START' => '2021-11-01', ],
        ];

print_r(array_diff(array_column($array1, 'title'), array_column($array2, 'title')));

Масив 1
Код:
Array
(
    [0] => Array
        (
            [title] => Студио
            [start] => 
            [end] => 
            [interval] => 
        )

    [1] => Array
        (
            [title] => Двойна стая
            [start] => 
            [end] => 
            [interval] => 
        )

    [2] => Array
        (
            [title] => Единична стая
            [start] => 
            [end] => 
            [interval] => 
        )

    [3] => Array
        (
            [title] => Тройна стая
            [start] => 
            [end] => 
            [interval] => 
        )

)

Масив 2
Код:
Array
(
    [0] => Array
        (
            [title] => Тройна стая
            [start] => DateTime Object
                (
                    [date] => 2021-11-01 00:00:00.000000
                    [timezone_type] => 3
                    [timezone] => UTC
                )

            [end] => DateTime Object
                (
                    [date] => 2021-11-25 00:00:00.000000
                    [timezone_type] => 3
                    [timezone] => UTC
                )

            [interval] => 24
        )
)


Резултат:
Array
(
[0] => Студио
[1] => Двойна стая
[2] => Единична стая
)



Проблема е там, че този резултат, трябва да е валиден до 25.11.2021г
Array
(
[0] => Студио
[1] => Двойна стая
[2] => Единична стая
)

След това трябва да изглежда така (от 25.11.2021 - напред):

Array
(
[0] => Студио
[1] => Двойна стая
[2] => Единична стая
[3] => Тройна стая
)
 
Струва ми се, че няма да се размина само с една бира да черпя ама ще видиме :lol: Таблицата с резервации:
Код:
CREATE TABLE `wp_calendar_reservation` (
  `cr_id` int(100) NOT NULL,
  `client_email` varchar(100) DEFAULT NULL,
  `client_phone` varchar(100) DEFAULT NULL,
  `client_arrival` varchar(100) NOT NULL,
  `client_departure` varchar(100) NOT NULL,
  `client_checkin` varchar(100) DEFAULT NULL,
  `client_checkout` varchar(100) DEFAULT NULL,
  `client_room` varchar(100) DEFAULT NULL,
  `client_adults` varchar(100) DEFAULT NULL,
  `client_children` varchar(100) DEFAULT NULL,
  `approve` int(11) NOT NULL DEFAULT 1 COMMENT '1=Active | 0=Inactive'
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

INSERT INTO `wp_calendar_reservation` (`cr_id`, `client_email`, `client_phone`, `client_arrival`, `client_departure`, `client_checkin`, `client_checkout`, `client_room`, `client_adults`, `client_children`, `approve`) VALUES
(1, 'test@gmail.com', '+11111111111111', '2021-11-01', '2021-12-30', 'Sunday, 1 Ноември, 2021', 'Tuesday, 3 Декември, 2021', 'Тройна стая', '1', '0', 0),
(2, 'test@gmail.com', '+11111111111111', '2021-11-12', '2021-11-28', 'Sunday, 1 Ноември, 2021', 'Tuesday, 30 Ноември, 2021', 'Двойна стая', '1', '0', 1),
(3, 'test@gmail.com', '+11111111111111', '2021-11-28', '2021-11-30', 'Sunday, 28 Ноември, 2021', 'Tuesday, 30 Ноември, 2021', 'Студио', '1', '0', 1);

ALTER TABLE `wp_calendar_reservation`
  ADD PRIMARY KEY (`cr_id`);

ALTER TABLE `wp_calendar_reservation`
  MODIFY `cr_id` int(100) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;

Наличните стаи:

Код:
$rooms = [
            ['title' => 'Студио' ],
            ['title' => 'Тройна стая'],
            ['title' => 'Двойна стая'],
            ['title' => 'Апартамент'],
            ['title' => 'Къща' ],
        ];
Това е календара:

Код:
<?php
if ( ! class_exists( 'Calendar' ) ) {
    class Calendar
    {

        private $active_year, $active_month, $active_day;
        private $events = [];

        public function __construct($date = null)
        {
            $this->active_year = $date != null ? date('Y', strtotime($date)) : date('Y');
            $this->active_month = $date != null ? date('m', strtotime($date)) : date('m');
            $this->active_day = $date != null ? date('d', strtotime($date)) : date('d');
        }

        public function add_event($txt, $date, $days = 1, $color = '', $checkout)
        {
            $color = $color ? ' ' . $color : $color;
            $this->events[] = [$txt, $date, $days, $color, $checkout];
        }

        public function __toString()
        {

            $num_days = date('t', strtotime($this->active_day . '-' . $this->active_month . '-' . $this->active_year));
            $num_days_last_month = date('j', strtotime('last day of previous month', strtotime($this->active_day . '-' . $this->active_month . '-' . $this->active_year)));
            $days = [6 => 'Sun', 0 => 'Mon', 1 => 'Tue', 2 => 'Wed', 3 => 'Thu', 4 => 'Fri', 5 => 'Sat'];
            $first_day_of_week = array_search(date('D', strtotime($this->active_year . '-' . $this->active_month . '-1')), $days);
            $html = '<div class="calendar_calendar">';
            $html .= '<div class="calendar_header">';
            $html .= '<div class="calendar_month-year">';
            $html .= date('F Y', strtotime($this->active_year . '-' . $this->active_month . '-' . $this->active_day));
            $html .= '</div>
<div class="calendar_my-legend">
    <div class="calendar_legend-scale">
        <ul class="calendar_legend-labels">
            <li><span style="background:red;"></span> Reserve</li>
            <li><span style="background:green;"></span> Free</li>
        </ul>
    </div>
</div>';
            $html .= '</div>';
            $html .= '<div class="calendar_days">';
            foreach ($days as $day) {
                $html .= '
                <div class="calendar_day_name">
                    '.$day.'
                </div>
            ';
            }
            for ($i = $first_day_of_week; $i > 0; $i--) {
                $html .= '
                <div class="calendar_day_num calendar_ignore">
                    ' . ($num_days_last_month - $i + 1) . '
                </div>
            ';
            }
            for ($i = 1; $i <= $num_days; $i++) {
                $selected = '';
                if ($i == $this->active_day) {
                    $selected = ' calendar_selected';
                }
                $html .= '<div class="calendar_day_num' . $selected . '">';
                $html .= '<span>' . $i . '</span>';

                    foreach ($this->events as $event) {
                        for ($d = 0; $d <= ($event[2] - 1); $d++) {
                            if (
                                (date('y-m-d',
                                        strtotime($this->active_year . '-' . $this->active_month . '-' . $i . ' -' . $d . ' day')
                                    ) == date('y-m-d', strtotime($event[1]))) &&
                                $event[4] > date('y-m-d',
                                    strtotime($this->active_year . '-' . $this->active_month . '-' . $i . ' -' . $d . ' day')
                                )
                            )

                            {
                                $html .= '<div class="calendar_event' . $event[3] . '">';
                                $html .= $event[0];
                                $html .= '</div>';
                            }
                        }
                    }
                $html .= '</div>';
            }
            for ($i = 1; $i <= (42 - $num_days - max($first_day_of_week, 0)); $i++) {
                $html .= '
                <div class="calendar_day_num calendar_ignore">
                    ' . $i . '
                </div>
            ';
            }
            $html .= '</div>';
            $html .= '</div>';
            return $html;
        }

    }
}

                //event['4'] == checkout
                //event['3'] == color
                //event['2'] == duration time
                //event['1'] == start date
                //event['0'] == room
$Calendar = new Calendar('2021-11-28');
$rooms = [
            ['title' => 'Студио' ],
            ['title' => 'Тройна стая'],
            ['title' => 'Двойна стая'],
            ['title' => 'Апартамент'],
            ['title' => 'Къща' ],
        ];
foreach ( $rooms as $room ) {

	$getCalendarQuery = $wpdb->get_results("SELECT * FROM `wp_calendar_reservation` WHERE `approve`='0';");
	foreach( $getCalendarQuery as $wp_calendar_row ) {
		$Calendar->add_event($wp_calendar_row->client_room, '2021-11-28', 3, 'red', '21-11-30');
	}
}
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Event Calendar</title>
    <link href="calendar_style.css" rel="stylesheet" type="text/css">
    <link href="calendar.css" rel="stylesheet" type="text/css">
</head>
<body>
<nav class="calendar_navtop">
    <div>
        <h1>Event Calendar</h1>
    </div>
</nav>
<div class="calendar_content calendar_home">
    <?=$Calendar?>
</div>
</body>
</html>

calendar_style.css
Код:
* {
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, "segoe ui", roboto, oxygen, ubuntu, cantarell, "fira sans", "droid sans", "helvetica neue", Arial, sans-serif;
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
body {
    background-color: #FFFFFF;
    margin: 0;
}
.calendar_navtop {
    background-color: #3b4656;
    height: 60px;
    width: 100%;
    border: 0;
}
.calendar_navtop div {
    display: flex;
    margin: 0 auto;
    width: 90%;
    height: 100%;
}
.calendar_navtop div h1, .calendar_navtop div a {
    display: inline-flex;
    align-items: center;
}
.calendar_navtop div h1 {
    flex: 1;
    font-size: 24px;
    padding: 0;
    margin: 0;
    color: #ebedee;
    font-weight: normal;
}
.calendar_navtop div a {
    padding: 0 20px;
    text-decoration: none;
    color: #c4c8cc;
    font-weight: bold;
}
.calendar_navtop div a i {
    padding: 2px 8px 0 0;
}
.calendar_navtop div a:hover {
    color: #ebedee;
}
.calendar_content {
    width: 90%;
    margin: 0 auto;
}
.calendar_content h2 {
    margin: 0;
    padding: 25px 0;
    font-size: 22px;
    border-bottom: 1px solid #ebebeb;
    color: #666666;
}

.calendar_my-legend .calendar_legend-title {
    text-align: left;
    margin-bottom: 5px;
    font-weight: bold;
    font-size: 90%;
}
.calendar_my-legend .calendar_legend-scale ul {
    margin: 0;
    margin-bottom: 5px;
    padding: 0;
    float: left;
    list-style: none;
}
.calendar_my-legend .calendar_legend-scale ul li {
    font-size: 80%;
    list-style: none;
    margin-left: 0;
    line-height: 18px;
    margin-bottom: 2px;
}
.calendar_my-legend ul.calendar_legend-labels li span {
    display: block;
    float: left;
    height: 16px;
    width: 30px;
    margin-right: 5px;
    margin-left: 0;
    border: 1px solid #999;
}
.calendar_my-legend .calendar_legend-source {
    font-size: 70%;
    color: #999;
    clear: both;
}
.calendar_my-legend a {
    color: #777;
}

calendar.css
Код:
.calendar_calendar {
    display: flex;
    flex-flow: column;
}
.calendar_calendar .calendar_header .calendar_month-year {
    font-size: 20px;
    font-weight: bold;
    color: #636e73;
    padding: 20px 0;
}
.calendar_calendar .calendar_days {
    display: flex;
    flex-flow: wrap;
}
.calendar_calendar .calendar_days .calendar_day_name {
    width: calc(100% / 7);
    border-right: 1px solid #2c7aca;
    padding: 20px;
    text-transform: uppercase;
    font-size: 12px;
    font-weight: bold;
    color: #818589;
    color: #fff;
    background-color: #448cd6;
}
.calendar_calendar .calendar_days .calendar_day_name:nth-child(7) {
    border: none;
}
.calendar_calendar .calendar_days .calendar_day_num {
    display: flex;
    flex-flow: column;
    width: calc(100% / 7);
    border-right: 1px solid #e6e9ea;
    border-bottom: 1px solid #e6e9ea;
    padding: 15px;
    font-weight: bold;
    color: #7c878d;
    cursor: pointer;
    min-height: 100px;
}
.calendar_calendar .calendar_days .calendar_day_num span {
    display: inline-flex;
    width: 30px;
    font-size: 14px;
}
.calendar_calendar .calendar_days .calendar_day_num .calendar_event {
    margin-top: 10px;
    font-weight: 500;
    font-size: 14px;
    padding: 3px 6px;
    border-radius: 4px;
    background-color: #f7c30d;
    color: #fff;
    word-wrap: break-word;
}
.calendar_calendar .calendar_days .calendar_day_num .calendar_event.green {
    background-color: #51ce57;
}
.calendar_calendar .calendar_days .calendar_day_num .calendar_event.blue {
    background-color: #518fce;
}
.calendar_calendar .calendar_days .calendar_day_num .calendar_event.red {
    background-color: #ce5151;
}
.calendar_calendar .calendar_days .calendar_day_num:nth-child(7n+1) {
    border-left: 1px solid #e6e9ea;
}
.calendar_calendar .calendar_days .calendar_day_num:hover {
    background-color: #fdfdfd;
}
.calendar_calendar .calendar_days .calendar_day_num.calendar_ignore {
    background-color: #fdfdfd;
    color: #ced2d4;
    cursor: inherit;
}
.calendar_calendar .calendar_days .calendar_day_num.calendar_selected {
    background-color: #f1f2f3;
    cursor: inherit;
}
 
Ticketa каза:
Резултат:
Array
(
[0] => Студио
[1] => Двойна стая
[2] => Единична стая
)



Проблема е там, че този резултат, трябва да е валиден до 25.11.2021г
Array
(
[0] => Студио
[1] => Двойна стая
[2] => Единична стая
)

След това трябва да изглежда така (от 25.11.2021 - напред):

Array
(
[0] => Студио
[1] => Двойна стая
[2] => Единична стая
[3] => Тройна стая
)

Защо? Кое казва, че трябва да филтрира различно за до 25 Ное 2021 и след 25 Ное 2021?
 

Горе