How can a loop be used to show the relationship between values in the array?

To show the relationship between values in an array using a loop, you can iterate through the array and compare each value with the next one. This can help you identify patterns, trends, or relationships between the values. By using a loop, you can easily access each element in the array and perform comparisons or calculations as needed.

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

for ($i = 0; $i < count($array) - 1; $i++) {
    $currentValue = $array[$i];
    $nextValue = $array[$i + 1];
    
    echo "The relationship between $currentValue and $nextValue is: ";
    
    if ($currentValue < $nextValue) {
        echo "increasing.\n";
    } elseif ($currentValue > $nextValue) {
        echo "decreasing.\n";
    } else {
        echo "equal.\n";
    }
}