I never know when I should be going directly to the database to do a search and when I should search within a PHP array where I've already loaded the database data. Anyway, there are times when it's clear that searching an array is necessary and I like to be able to use a search which is essentially the same as an SQL query like:
SELECT `field_name` FROM table_name WHERE `field2` = 'something' AND `field3` = 'other' AND `field4` = 'another'
to do this I used the following function:
function searcharray2($value, $key, $value2, $key2, $value3, $key3, $array) {
foreach ($array as $k => $val) {
if ($val[$key] == $value) {
foreach ($array as $m => $val) {
if ($val[$key2] == $value2 AND $k==$m) {
foreach ($array as $n => $val) {
if ($val[$key3] == $value3 AND $k==$n) {
return $k;
}
}
}
}
}
}
return null;
}