rubo77
rubo77

Reputation: 20845

How do I get an array with all elements with the same key?

I have an array

<?php
array ( 
0 => array ( 'name' => 'id', 'type' => 'integer', 'null' => 'NO', ), 
1 => array ( 'name' => 'strasse', 'type' => 'string', 'null' => 'YES', ), 
#...
)

How do I get an array with all the names or with only all the types?

like:

array('id','name',...)

Upvotes: 0

Views: 47

Answers (1)

John Conde
John Conde

Reputation: 219824

In PHP 5.5 you can use array_column()

$names = array_column($array, 'name');

// array('id','strasse',...)

Upvotes: 2

Related Questions