How can one automatically assign values from an array to individual variables in PHP?

To automatically assign values from an array to individual variables in PHP, you can use the list() function. This function assigns variables as if they were an array. The number of variables must match the number of elements in the array, or PHP will throw an error. This is a convenient way to quickly assign values from an array to separate variables without having to manually index each element.

$array = [1, 2, 3];
list($var1, $var2, $var3) = $array;

echo $var1; // Output: 1
echo $var2; // Output: 2
echo $var3; // Output: 3