How can a column be stored in an array in PHP?
To store a column from a multidimensional array in PHP, you can use array_column() function. This function extracts a single column from the array and returns it as a new array. You need to specify the array you want to extract the column from, and the key of the column you want to extract.
// Sample multidimensional array
$data = [
['id' => 1, 'name' => 'Alice'],
['id' => 2, 'name' => 'Bob'],
['id' => 3, 'name' => 'Charlie']
];
// Extracting the 'name' column from the array
$names = array_column($data, 'name');
// Printing the extracted column
print_r($names);