How can you create and assign values to an array in PHP?

To create and assign values to an array in PHP, you can simply declare the array variable and assign values to it using square brackets. You can assign values to specific keys in the array by specifying the key within the square brackets. Alternatively, you can use the array() function to create an array and assign values to it in one step.

// Creating an array and assigning values to it
$array1 = [1, 2, 3, 4, 5];

// Assigning values to specific keys in the array
$array2 = [];
$array2[0] = 'apple';
$array2[1] = 'banana';
$array2[2] = 'orange';

// Using the array() function to create an array with values
$array3 = array('red', 'green', 'blue');