How can an array be assigned to a variable in PHP?

To assign an array to a variable in PHP, you simply create the array and then assign it to the variable using the assignment operator (=). This allows you to store the array in a variable for easy access and manipulation in your code.

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

// Assigning the array to a variable
$myArray = $array;

// Accessing the array through the variable
echo $myArray[2]; // Outputs 3