$data = [
['id' => 1, 'name' => 'Alice'],
['id' => 2, 'name' => 'Bob'],
['id' => 3, 'name' => 'Charlie']
];
$names = array_column($data, 'name');
print_r($names);
class User {
public $id;
public $name;
public function __construct($id, $name) {
$this->id = $id;
$this->name = $name;
}
}
$users = [
new User(1, 'Alice'),
new User(2, 'Bob'),
new User(3, 'Charlie')
];
$names = array_column($users, 'name');
print_r($names);
$data = [
'id' => 1,
'name' => 'Alice',
'age' => 25
];
$values = array_values($data);
print_r($values);