What is the best way to compare the last key with the following one in a PHP script?

When comparing the last key with the following one in a PHP script, you can iterate over the array using a loop and keep track of the previous key to compare it with the current key. One way to achieve this is by using a `foreach` loop and storing the previous key in a variable before updating it with the current key in each iteration.

$array = [1, 2, 3, 4, 5];

$prevKey = null;
foreach ($array as $key => $value) {
    if ($prevKey !== null) {
        // Compare the previous key with the current key
        if ($prevKey < $key) {
            echo "The previous key is less than the current key\n";
        } else {
            echo "The previous key is greater than or equal to the current key\n";
        }
    }
    $prevKey = $key;
}