Q:

How do I compare pairs of elements in a single array?

I have an assignment where I'm asked to take a string, explode it into an array, and then compare every two values of said array. They said we should you use the array_shift() function to take the first value of the array and compare it to the "new" first element. So basically, we have to compare [0] with [1], [2] with [3], and so on. For a more visual representation, this is what I have so far:
/*Constant*/
define("STRING_END", 7);

/*This functions prints two domino tiles; it's not really part of the question.*/
    function printTiles($left, $right){
        echo "<img src='".$left."_.png'/>", "<img src='_".$right.".png'/>";
    }

    /* Main Algorithm */
    $text = "1,2,4,4,4,6,7"; //the goal is to check if every two elements of the string are the same
    $arrayedText= explode(",", $text); //now I have the array with all the numbers from the string

    $doubleTiles = false; //this is just to check when double tiles have been found

    while ($arrayedText[1] != STRING_END){ //so while the next position is not a "7"
        $firstTile = array_shift($arrayedText); //the first tile is the first element of the array
        $nextTile = $arrayedText[0];        //the next tile is the "new" first element of the array after having removed the other one
        if($firstTile == $nextTile){ //if these two tiles are the same
            $doubleTiles = true; 
            printTiles($firstTile, $nextTile); //run the function and print the tiles on screen
        }
    }

So the issue I'm  having is that it's basically comparing [0] with [1] and checking if they're the same, which is fine. But then it's checking [1] and [2] and checking if they're the same. Meaning that it's going to compare [3] and [4] and detect it as a double pair; which wouldn't be correct. I basically want a way to skip to the next pair of numbers. 
Hopefully I've managed to get my point/question across. Any help would be much appreciated!

A:

If you are after finding doubles in your string or exploded array, we could shift twice and then compare for equality.  We stop if either of shifts return null (null implies empty or not an array).
<?php

$items = [1,2,4,4,4,6,7];

while
(
       ($a = array_shift($items)) !== null
    && ($b = array_shift($items)) !== null
) {
    if($a == $b)
        echo 'Double: ', $a, ' ', $b, "\n";
}

Output:
 Double: 4 4

