Recently, while working on cutting down mysql queries, I came across 2 functions which were on php.net
*I am not the author of this code*
I simply changed a few things around.
Installation:
open up /includes/functions/html_output.php
towards the end insert these 2 functions:
////
// Two very nice functions for searching array by either a key or by a value
function tep_search_array_by_key($array, $key, $value) {
$results = array();
if (is_array($array)) {
if ($array[$key] == $value) {
$results[] = $array;
}
foreach ($array as $subarray) {
$results = array_merge($results, tep_search_array_by_key($subarray, $key, $value));
}
}
return $results;
}
function tep_search_array_by_value($array, $value) {
$results = array();
if (is_array($array)) {
$found = array_search($value,$array);
if ($found) {
$results[] = $found;
}
foreach ($array as $subarray) {
$results = array_merge($results, tep_search_array_by_value($subarray, $value));
}
}
return $results;
}
These functions are meant to be used by those who understand it's arrays. Basically the idea is that in shot you can store data from mysql queries in an array and the loop them and do a search either by key or value. I am sure there are numerous places it can be used in the admin end as well but I haven't gotten around to that yet.