Php array search multiple columns
how can I search an array matching two or more values? Show
I would like to search for "mitarbeiterid" and "von". This is just a example, in this array are a few hundred entries. I only know how to search for e.g. "von" but how to combine the search parameters?
yivi 37.5k18 gold badges93 silver badges119 bronze badges asked Sep 1, 2015 at 13:50
1 Have a look at
To use outside variables, inside lambda function, use
answered Sep 1, 2015 at 13:54
viralviral 3,65017 silver badges32 bronze badges 3 (PHP 5 >= 5.5.0, PHP 7, PHP 8) array_column — Return the values from a single column in the input array Descriptionarray_column(array Parametersarray A multi-dimensional array or an array of objects from which to pull a column of values from. If an array of objects is provided, then public properties can be directly pulled. In order for protected or private properties to be pulled, the class must implement both the __get() and __isset() magic methods. column_key The column of values to return. This value may be an integer key of the column you wish to retrieve, or it may be a string key name for an associative array or property name. It may also be index_key
The column to use as the index/keys for the returned array. This value may be the integer key of the column, or it may be the string key name. The value is cast as usual for array keys (however, prior to PHP 8.0.0, objects supporting conversion to string were also allowed). Return ValuesReturns an array of values representing a single column from the input array. Changelog
ExamplesExample #1 Get the column of first names from a recordset
The above example will output: Array ( [0] => John [1] => Sally [2] => Jane [3] => Peter ) Example #2 Get the column of last names from a recordset, indexed by the "id" column
The above example will output: Array ( [2135] => Doe [3245] => Smith [5342] => Jones [5623] => Doe ) Example #3 Get the column of usernames from the public "username" property of an object
__construct(string $username) The above example will output: Array ( [0] => user 1 [1] => user 2 [2] => user 3 ) Example #4 Get the column of names from the private "name" property of an object using the magic __get() method.
__construct(string $name) The above example will output: Array ( [0] => Fred [1] => Jane [2] => John ) If __isset() is not provided, then an empty array will be returned. mohanrajnr at gmail dot com ¶ 7 years ago
WARrior ¶ 8 years ago
balbuf ¶ 4 years ago
ff2 AT hotmail DOT co DOT uk ¶ 4 years ago
$indexkey === null) { $result[] = $val; } yangmeishu at live dot com ¶ 2 years ago
= [ till at etill dot net ¶ 7 years ago
nino at recgr dot com ¶ 6 years ago
miguelfzarth at gmail dot com ¶ 6 years ago
antonfedonjuk at gmail dot com ¶ 7 years ago
Anonymous ¶ 6 years ago
$index_key !== null) { Carlos Granados ¶ 5 years ago
array_intersect_key($data, $keep); Hiranmoy Chatterjee ¶ 6 months ago
benjam ¶ 6 years ago
= array( oleg dot bolden at gmail dot com ¶ 4 months ago
$output; Sbastien ¶ 5 months ago
1184427175 at qq dot com ¶ 5 years ago
Nolan chou ¶ 6 years ago
kaspar dot wilbuer at web dot de ¶ 6 years ago
katrinaelaine6 at gmail dot com ¶ 5 years ago
= [ kiler129 @ nowhere ¶ 7 years ago
hypxm at qq dot com ¶ 7 years ago
marianbucur17 at yahoo dot com ¶ 7 years ago
robbieaverill[at]gmail.com ¶ 7 years ago
myles at smyl dot es ¶ 7 years ago
greensea ¶ 6 years ago
$index_key === NULL || !isset($v[$index_key])) { coviex ¶ 7 years ago
robsonvnasc at gmail dot com ¶ 5 years ago
Dominik59 ¶ 5 years ago
How to search in multidimensional array in php?Multidimensional array search using array_search() method:
The array_search() is an inbuilt function which searches for a given value related to the given array column/key. This function only returns the key index instead of a search path.
What is array_ column in php?array_column() returns the values from a single column of the array , identified by the column_key . Optionally, an index_key may be provided to index the values in the returned array by the values from the index_key column of the input array.
What is the multidimensional array in php?A multidimensional array is an array containing one or more arrays. PHP supports multidimensional arrays that are two, three, four, five, or more levels deep. However, arrays more than three levels deep are hard to manage for most people.
What is the difference between In_array and Array_search?The main difference between both the functions is that array_search() usually returns either key or index whereas in_array() returns TRUE or FALSE according to match found in search. Value: It specifies the value that needs to be searched in an array.
|