Example 1 — Getting One Column
Collect the name of every user from a list of records.
<?php
$users = [
['id' => 1, 'name' => 'Asha'],
['id' => 2, 'name' => 'Ravi'],
['id' => 3, 'name' => 'Meena'],
];
print_r(array_column($users, 'name')); How It Works
- $users is a list of three rows and each row is an associative array.
- array_column($users, 'name') reads the 'name' value from every row.
- No index key was given, so the result uses the keys 0, 1 and 2.
- print_r() shows the three names in their original order.

