What are some alternative methods to achieve the functionality of array_column in PHP?

The array_column function in PHP is used to extract a single column from a multi-dimensional array. If you need to achieve the same functionality without using array_column, you can loop through the array and build a new array with the desired column values.

// Sample multi-dimensional array
$data = [
    ['id' => 1, 'name' => 'Alice'],
    ['id' => 2, 'name' => 'Bob'],
    ['id' => 3, 'name' => 'Charlie']
];

// Alternative method to achieve array_column functionality
$columnValues = [];
$columnName = 'name';

foreach ($data as $row) {
    $columnValues[] = $row[$columnName];
}

print_r($columnValues);