In PHP, what are some alternative methods for setting up arrays in controllers?

When setting up arrays in controllers in PHP, an alternative method is to use the array() function or the shorthand [] syntax to declare and initialize arrays. This can make the code more readable and concise compared to using the array() constructor. Additionally, you can use the compact() function to create an array from a list of variables.

// Using array() function to set up an array
$data = array('name' => 'John', 'age' => 30, 'city' => 'New York');

// Using [] shorthand syntax to set up an array
$data = ['name' => 'John', 'age' => 30, 'city' => 'New York'];

// Using compact() function to create an array from variables
$name = 'John';
$age = 30;
$city = 'New York';
$data = compact('name', 'age', 'city');