[PHP] Extract one column from a multidimensional array

Created on November 30, 2026

Use array_column to collect the values for a given key from an array of rows. This example extracts the names.

<?php

$users = [
    ['id' => 101, 'name' => 'Taro', 'role' => 'admin'],
    ['id' => 102, 'name' => 'Jiro', 'role' => 'user'],
    ['id' => 103, 'name' => 'Saburo', 'role' => 'user'],
];

// Extract only the values for the 'name' key
$names = array_column($users, 'name');

var_dump($names);

Output

array(3) {
  [0]=>
  string(4) "Taro"
  [1]=>
  string(4) "Jiro"
  [2]=>
  string(6) "Saburo"
}

Choose the keys in the result

Pass a third argument to select the column PHP should use for the result's keys. This example indexes the names by user ID.

<?php

$users = [
    ['id' => 101, 'name' => 'Taro', 'role' => 'admin'],
    ['id' => 102, 'name' => 'Jiro', 'role' => 'user'],
    ['id' => 103, 'name' => 'Saburo', 'role' => 'user'],
];

// Extract the 'name' values and key the result by 'id'
$names_indexed_by_id = array_column($users, 'name', 'id');

var_dump($names_indexed_by_id);

Output

array(3) {
  [101]=>
  string(4) "Taro"
  [102]=>
  string(4) "Jiro"
  [103]=>
  string(6) "Saburo"
}
PHP