$users = [ ['id' => 1, 'name' => 'Alice'], ['id' => 2, 'name' => 'Bob'], ['id' => 3, 'name' => 'Charlie'], ]; To get all the names: $names = array_column($users, 'name'); // Result: ['Alice', 'Bob', 'Charlie'] Want to index them by ID? $names = array_column($users, 'name', 'id'); // Result: [1 => 'Alice', 2 => 'Bob', 3 => 'Charlie']
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter