Comparing multiple arrays for the same values
<p>I have the following code that produces an array.</p>

<p>I need to split that array up and compare the resulting arrays against one another.</p>

<p>I only need to compare arrays that are next to one another in order. </p>

<p>So the first and second, second and third, so on.. I can build another array to store the order that needs to be compared if that helps. I just haven't a clue how to check them like this.</p>

<p>The goal is to ensure that the arrays on either side of one another do not contain the same $racer_id</p>

<p>It's for a scoring app for a race track and one racer can not be in races that are one after the other.</p>

<p>Can someone give me a shove in the right direction?</p>

<p>** there will only be one $event_id, with multiple $class_id and $racer_id.</p>

<pre><code>&lt;?php
function getEventClasses()
{
    global $db;
    global $event_id;
    try {
        $getEventClasses = $db-&gt;prepare('SELECT class_id
                                     FROM tbl_event_classes
                                     WHERE event_id = :event_id
                                     ORDER BY sort');
        $getEventClasses-&gt;bindValue(':event_id', $event_id);
        $getEventClasses-&gt;execute();
    } catch (PDOException $ex) {
        echo 'An Error occurred!&lt;br&gt;';
        //user friendly message
        $ex-&gt;getMessage();
        echo $ex;
        exit;
    }
    $eventClasses = [];
    while ($r = $getEventClasses-&gt;fetch(PDO::FETCH_ASSOC)) {
        $eventClasses[] = [
            'class_id' =&gt; $r['class_id']
        ];
    }
    return $eventClasses;
}

function getEntries($class_id)
{
    global $db;
    global $event_id;
    try {
        $getEntries = $db-&gt;prepare('SELECT tbl_event_entries.racer_id, 
                                   tbl_event_entries.class_id, 
                                   tbl_event_entries.event_id, 
                                   tbl_event_classes.class_type, 
                                   tbl_event_classes.points_class, 
                                   tbl_moto_order.moto_nbr
                            FROM tbl_moto_order 
                            INNER JOIN (tbl_event_entries 
                             LEFT JOIN tbl_event_classes 
                                    ON (tbl_event_entries.event_id = tbl_event_classes.event_id)
                                    AND (tbl_event_entries.class_id = tbl_event_classes.class_id)) 
                                    ON (tbl_moto_order.class_id = tbl_event_entries.class_id)
                                    AND (tbl_moto_order.event_id = tbl_event_entries.event_id)
                            WHERE tbl_event_entries.event_id = :event_id
                            AND tbl_event_entries.racer_id != "9999"
                            AND tbl_event_entries.class_id = :class_id');
        $getEntries-&gt;bindValue(':event_id', $event_id);
        $getEntries-&gt;bindValue(':class_id', $class_id);
        $getEntries-&gt;execute();
    } catch (PDOException $ex) {
        echo 'An Error occurred!&lt;br&gt;';
        //user friendly message
        $ex-&gt;getMessage();
        echo $ex;
        exit;
    }
    $eventEntries = [];
    while ($r = $getEntries-&gt;fetch(PDO::FETCH_ASSOC)) {
        $eventEntries[] = [
            'racer_id'     =&gt; $r['racer_id'],
            'class_id'     =&gt; $r['class_id'],
            'event_id'     =&gt; $r['event_id'],
            'class_type'   =&gt; $r['class_type'],
            'points_class' =&gt; $r['points_class'],
            'moto_nbr'     =&gt; $r['moto_nbr']
        ];
    }
    return $eventEntries;
}

$eventClasses = getEventClasses();
foreach ($eventClasses as $eventClass) {
    $eventEntries = getEntries($eventClass['class_id']);
    foreach ($eventEntries as $eventEntry) {
        $runningClasses[$eventClass['class_id']][] = [
            'racer_id'     =&gt; $eventEntry['racer_id'],
            'event_id'     =&gt; $eventEntry['event_id'],
            'class_type'   =&gt; $eventEntry['class_type'],
            'points_class' =&gt; $eventEntry['points_class'],
            'moto_nbr'     =&gt; $eventEntry['moto_nbr']
        ];
    }
}
foreach ($runningClasses as $class) {
    $f-&gt;printr($class);
}
?&gt;
</code></pre>

<p>the array:</p>

<pre><code>     Array
 (
     [17] =&gt; Array
         (
             [0] =&gt; Array
                 (
                     [racer_id] =&gt; 95
                     [event_id] =&gt; 326
                     [class_type] =&gt; A
                     [points_class] =&gt; 17
                     [moto_nbr] =&gt; 3
                 )
             [1] =&gt; Array
                 (
                     [racer_id] =&gt; 350
                     [event_id] =&gt; 326
                     [class_type] =&gt; A
                     [points_class] =&gt; 17
                     [moto_nbr] =&gt; 3
                 )
             [2] =&gt; Array
                 (
                     [racer_id] =&gt; 493
                     [event_id] =&gt; 326
                     [class_type] =&gt; A
                     [points_class] =&gt; 17
                     [moto_nbr] =&gt; 3
                 )
             [3] =&gt; Array
                 (
                     [racer_id] =&gt; 295
                     [event_id] =&gt; 326
                     [class_type] =&gt; A
                     [points_class] =&gt; 17
                     [moto_nbr] =&gt; 3
                 )
             [4] =&gt; Array
                 (
                     [racer_id] =&gt; 1142
                     [event_id] =&gt; 326
                     [class_type] =&gt; A
                     [points_class] =&gt; 17
                     [moto_nbr] =&gt; 3
                 )
             [5] =&gt; Array
                 (
                     [racer_id] =&gt; 628
                     [event_id] =&gt; 326
                     [class_type] =&gt; A
                     [points_class] =&gt; 17
                     [moto_nbr] =&gt; 3
                 )
         )
     [14] =&gt; Array
         (
             [0] =&gt; Array
                 (
                     [racer_id] =&gt; 1142
                     [event_id] =&gt; 326
                     [class_type] =&gt; A
                     [points_class] =&gt; 14
                     [moto_nbr] =&gt; 4
                 )
             [1] =&gt; Array
                 (
                     [racer_id] =&gt; 162
                     [event_id] =&gt; 326
                     [class_type] =&gt; A
                     [points_class] =&gt; 14
                     [moto_nbr] =&gt; 4
                 )
             [2] =&gt; Array
                 (
                     [racer_id] =&gt; 151
                     [event_id] =&gt; 326
                     [class_type] =&gt; A
                     [points_class] =&gt; 14
                     [moto_nbr] =&gt; 4
                 )
             [3] =&gt; Array
                 (
                     [racer_id] =&gt; 1176
                     [event_id] =&gt; 326
                     [class_type] =&gt; A
                     [points_class] =&gt; 14
                     [moto_nbr] =&gt; 4
                 )
             [4] =&gt; Array
                 (
                     [racer_id] =&gt; 401
                     [event_id] =&gt; 326
                     [class_type] =&gt; A
                     [points_class] =&gt; 14
                     [moto_nbr] =&gt; 4
                 )
             [5] =&gt; Array
                 (
                     [racer_id] =&gt; 264
                     [event_id] =&gt; 326
                     [class_type] =&gt; A
                     [points_class] =&gt; 14
                     [moto_nbr] =&gt; 4
                 )
             [6] =&gt; Array
                 (
                     [racer_id] =&gt; 797
                     [event_id] =&gt; 326
                     [class_type] =&gt; A
                     [points_class] =&gt; 14
                     [moto_nbr] =&gt; 4
                 )
             [7] =&gt; Array
                 (
                     [racer_id] =&gt; 124
                     [event_id] =&gt; 326
                     [class_type] =&gt; A
                     [points_class] =&gt; 14
                     [moto_nbr] =&gt; 4
                 )
             [8] =&gt; Array
                 (
                     [racer_id] =&gt; 29
                     [event_id] =&gt; 326
                     [class_type] =&gt; A
                     [points_class] =&gt; 14
                     [moto_nbr] =&gt; 4
                 )
             [9] =&gt; Array
                 (
                     [racer_id] =&gt; 74
                     [event_id] =&gt; 326
                     [class_type] =&gt; A
                     [points_class] =&gt; 14
                     [moto_nbr] =&gt; 4
                 )
             [10] =&gt; Array
                 (
                     [racer_id] =&gt; 117
                     [event_id] =&gt; 326
                     [class_type] =&gt; A
                     [points_class] =&gt; 14
                     [moto_nbr] =&gt; 4
                 )
             [11] =&gt; Array
                 (
                     [racer_id] =&gt; 408
                     [event_id] =&gt; 326
                     [class_type] =&gt; A
                     [points_class] =&gt; 14
                     [moto_nbr] =&gt; 4
                 )
             [12] =&gt; Array
                 (
                     [racer_id] =&gt; 501
                     [event_id] =&gt; 326
                     [class_type] =&gt; A
                     [points_class] =&gt; 14
                     [moto_nbr] =&gt; 4
                 )
             [13] =&gt; Array
                 (
                     [racer_id] =&gt; 1125
                     [event_id] =&gt; 326
                     [class_type] =&gt; A
                     [points_class] =&gt; 14
                     [moto_nbr] =&gt; 4
                 )
         )
     [8] =&gt; Array
         (
             [0] =&gt; Array
                 (
                     [racer_id] =&gt; 1180
                     [event_id] =&gt; 326
                     [class_type] =&gt; A
                     [points_class] =&gt; 8
                     [moto_nbr] =&gt; 6
                 )
         )
     [16] =&gt; Array
         (
             [0] =&gt; Array
                 (
                     [racer_id] =&gt; 73
                     [event_id] =&gt; 326
                     [class_type] =&gt; A
                     [points_class] =&gt; 16
                     [moto_nbr] =&gt; 12
                 )
             [1] =&gt; Array
                 (
                     [racer_id] =&gt; 9
                     [event_id] =&gt; 326
                     [class_type] =&gt; A
                     [points_class] =&gt; 16
                     [moto_nbr] =&gt; 12
                 )
             [2] =&gt; Array
                 (
                     [racer_id] =&gt; 525
                     [event_id] =&gt; 326
                     [class_type] =&gt; A
                     [points_class] =&gt; 16
                     [moto_nbr] =&gt; 12
                 )
         )
     [13] =&gt; Array
         (
             [0] =&gt; Array
                 (
                     [racer_id] =&gt; 1089
                     [event_id] =&gt; 326
                     [class_type] =&gt; A
                     [points_class] =&gt; 13
                     [moto_nbr] =&gt; 15
                 )
             [1] =&gt; Array
                 (
                     [racer_id] =&gt; 73
                     [event_id] =&gt; 326
                     [class_type] =&gt; A
                     [points_class] =&gt; 13
                     [moto_nbr] =&gt; 15
                 )
             [2] =&gt; Array
                 (
                     [racer_id] =&gt; 162
                     [event_id] =&gt; 326
                     [class_type] =&gt; A
                     [points_class] =&gt; 13
                     [moto_nbr] =&gt; 15
                 )
             [3] =&gt; Array
                 (
                     [racer_id] =&gt; 264
                     [event_id] =&gt; 326
                     [class_type] =&gt; A
                     [points_class] =&gt; 13
                     [moto_nbr] =&gt; 15
                 )
             [4] =&gt; Array
                 (
                     [racer_id] =&gt; 797
                     [event_id] =&gt; 326
                     [class_type] =&gt; A
                     [points_class] =&gt; 13
                     [moto_nbr] =&gt; 15
                 )
             [5] =&gt; Array
                 (
                     [racer_id] =&gt; 422
                     [event_id] =&gt; 326
                     [class_type] =&gt; A
                     [points_class] =&gt; 13
                     [moto_nbr] =&gt; 15
                 )
             [6] =&gt; Array
                 (
                     [racer_id] =&gt; 1176
                     [event_id] =&gt; 326
                     [class_type] =&gt; A
                     [points_class] =&gt; 13
                     [moto_nbr] =&gt; 15
                 )
             [7] =&gt; Array
                 (
                     [racer_id] =&gt; 76
                     [event_id] =&gt; 326
                     [class_type] =&gt; A
                     [points_class] =&gt; 13
                     [moto_nbr] =&gt; 15
                 )
             [8] =&gt; Array
                 (
                     [racer_id] =&gt; 1136
                     [event_id] =&gt; 326
                     [class_type] =&gt; A
                     [points_class] =&gt; 13
                     [moto_nbr] =&gt; 15
                 )
         )
     [5] =&gt; Array
         (
             [0] =&gt; Array
                 (
                     [racer_id] =&gt; 600
                     [event_id] =&gt; 326
                     [class_type] =&gt; Y
                     [points_class] =&gt; 5
                     [moto_nbr] =&gt; 16
                 )
             [1] =&gt; Array
                 (
                     [racer_id] =&gt; 1143
                     [event_id] =&gt; 326
                     [class_type] =&gt; Y
                     [points_class] =&gt; 5
                     [moto_nbr] =&gt; 16
                 )
         )
     [10] =&gt; Array
         (
             [0] =&gt; Array
                 (
                     [racer_id] =&gt; 421
                     [event_id] =&gt; 326
                     [class_type] =&gt; A
                     [points_class] =&gt; 10
                     [moto_nbr] =&gt; 19
                 )
             [1] =&gt; Array
                 (
                     [racer_id] =&gt; 1219
                     [event_id] =&gt; 326
                     [class_type] =&gt; A
                     [points_class] =&gt; 10
                     [moto_nbr] =&gt; 19
                 )
         )
 )
</code></pre>