slightly cut down version not using regexp:
PHP Code:
function findKeys($array,$field,$value) {
foreach ($array as $key=>$info) {
if ($info[$field] == $value) {
$matches[] = $key;
}
}
return $matches;
}
now you just pass it as a function like so:
PHP Code:
$matches = findKeys($db,'name','John');
To find keys of all elements where name == 'John' in the arrray $db.
Also untested but i cant see any obvious mistakes off hand, i'll test it if i get a chance in a minute.
EDIT:
PHP Code:
<?php
function findKeys($array,$field,$condition,$value) {
foreach ($array as $key=>$info) {
eval('if ($info[$field] '.$condition.' $value) {
$matches[] = $key;
}');
}
return $matches;
}
$db[0]['name'] = 'john';
$db[0]['age'] = 18;
$db[0]['gender'] = 'm';
$db[1]['name'] = 'janet';
$db[1]['age'] = 17;
$db[1]['gender'] = 'f';
print_r(findKeys($db,'age','>','10'));
?>
I re-read you post and noticed the bit about the condition, so i altered my function slightly, this example inputs your sample data and outputs the results, syntax is now
PHP Code:
findKeys(<the array>,<field to search>,<condtion>,<value>);