What are the benefits of using arrays in PHP for storing and comparing variables?

Using arrays in PHP for storing and comparing variables allows for efficient organization and manipulation of data. Arrays provide a way to store multiple values in a single variable, making it easier to access and iterate through them. Additionally, arrays can be sorted, filtered, and searched to easily compare values and perform operations on them.

// Storing variables in an array
$numbers = [5, 3, 8, 2, 1];

// Comparing variables in an array
if (in_array(3, $numbers)) {
    echo "3 is found in the array";
}

// Sorting array
sort($numbers);

// Looping through array
foreach ($numbers as $number) {
    echo $number . " ";
}