OBJECTIVE: find whether a given value is present at least once in
any of the input arrays.
function anyArrayItem($arrayOrArrayOfArrays=array(), $item=''){
$firstRun=array_search($item, $arrayOrArrayOfArrays, true);
if($firstRun!==false){return $firstRun;};//any
foreach($arrayOrArrayOfArrays as $arr){
if( is_array($arr) && (($aSearch=array_search($item, $arr, true))!==false) ){return $aSearch;};
}
return false;
}
Remove colors
INPUTS: an array, or an array of arrays if you need to perform the search on a set of arrays.
RETURNS: boolean
false if the item does not meet the conditions, or a Number representing the index of the first item instance found.
CAVEATS: if the searched item is present more than once, only the index of the
first found instance is returned; moreover, if the passed first argument is an array of arrays, such returned number does not reveal in which of the nested array the first instance was found.
The search requires equivalence with the given searched item value and with its
data type too: to override this (not recommended) remove the third parameter (and its leading comma) from the function
array_search wherever it appears in the code.
Unfortunately, the searches are all
case sensitive.
OBJECTIVE: find whether a
given value is present in
all of the input arrays.
function allArraysItem($arrayOrArrayOfArrays=array(), $item=''){
$firstRun=array_search($item, $arrayOrArrayOfArrays, true);
if($firstRun===false){return false;};//all
foreach($arrayOrArrayOfArrays as $arr){
if( is_array($arr) && array_search($item, $arr, true)===false ){return false;};
}
return true;
}
Remove colors
INPUTS: an array, or an array of arrays if you need to perform the search on a set of arrays.
RETURNS: boolean
false if the item does not meet the conditions, or boolean
true.
CAVEATS: the search requires equivalence with the given searched item value and with its
data type too: to override this (not recommended) remove the third parameter (and its leading comma) from the function
array_search wherever it appears in the code.
Unfortunately the searches are all
case sensitive.
A note: this routine is conceptually different from
Php To Find Identical Items Present In All The Input Arrays: Intersect Arrays insofar as in the latter the item(s) to be found in all the arrays are
not passed as a
given input to
look for, but are investigated and
drawn from the input arrays.