Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array_column with index instead of associative key

Tags:

php

How exactly can I apply array_column always getting the first column of an array instead of getting the column by name? This is:

array_column($array,[0])

instead of

array_column($array,"key");
like image 704
Fane Avatar asked Dec 09 '15 20:12

Fane


People also ask

How to get value of a column from array PHP?

The array_column() function returns the values from a single column in the input array.

How get key of multidimensional array in PHP?

array_keys() returns the keys, numeric and string, from the array . If a search_value is specified, then only the keys for that value are returned. Otherwise, all the keys from the array are returned.

What is key in associative array?

An associative array is an array with string keys rather than numeric keys. Associative arrays are dynamic objects that the user redefines as needed. When you assign values ​​to keys in a variable of type Array, the array is transformed into an object, and it loses the attributes and methods of Array.


1 Answers

Try

array_column($array, array_shift(array_keys($array)));

from Return first key of associative array in PHP

Hope can help! :)

like image 94
Rafael Basso Avatar answered Oct 20 '22 15:10

Rafael Basso