sigil88
6/19/2018 - 8:49 PM

array example (fun .... )

<style>* {font-family: "Courier"}</style>
<?php 
    $combinedArray = NULL;
    $defaultArray = [
        0 => [
            "id" => 1,
            "day" => "MONDAY",
            "AM" => "USER MON AM",
            "PM" => "USER MON PM",
            "overrideDate" => NULL
        ],

        1 => [
            "id" => 2,
            "day" => "TUESDAY",
            "AM" => "USER TUES AM",
            "PM" => "USER TUES PM",
            "overrideDate" => NULL
        ],

        2 => [
            "id" => 3,
            "day" => "WEDNESDAY",
            "AM" => "USER WED AM",
            "PM" => "USER WED PM",
            "overrideDate" => NULL
        ]
    ];

    $overrideArray = [
        0 => [
            "id" => 10,
            "day" => "MONDAY",
            "AM" => "OVERRIDE AM",
            "PM" => "OVERRIDE PM",
            "overrideDate" => "2018-06-01"
        ],

        1 => [
            "id" => 20,
            "day" => "WEDNESDAY",
            "AM" => "OVERRIDE AM",
            "PM" => "OVERRIDE PM",
            "overrideDate" => "2018-06-01"
        ]
    ];

    foreach ($overrideArray as $key => $day) {
        // var_dump($day['day']);

        foreach ($defaultArray as $defKey => $defDay) {
            if ($defDay['day'] === $day['day']) {
                $defaultArray[$defKey]['AM'] = $day['AM'];
                $defaultArray[$defKey]['PM'] = $day['PM'];
            }
        }
    }
?>

<!-- <h3>COMBINED</h3>
<pre><?php //var_dump($combinedArray); ?></pre>
<hr> -->

<h3>DEFAULT</h3>
<pre><?php var_dump($defaultArray); ?></pre>
<hr>

<h3>OVERRIDE</h3>
<pre><?php var_dump($overrideArray); ?></pre>
<hr>