Instead of your current $arr
structure, you'd better have an associative array, where the keys uniquely identify the value.
If you need to search that array several times, you might still save time if you would spend some time to create such associative array from your existing array:
$arr2 = array(
array( "a"=>12,"b"=>5,"c"=>16),
array("d"=>1,"g"=>5,"c"=>16),
array("a"=>12,"c"=>5,"e"=>3)
);
// use key/value pairs, with as key the JSON-encoding of the value
// Note: this will take some time for very large arrays:
foreach ($arr2 as $sub) {
ksort($sub); // need to sort the keys to make sure we can find a match when needed
$hash[json_encode($sub)] = $sub;
}
// function to see whether the value is in the array: this will be fast!
function inHash($hash, $sub) {
ksort($sub);
return isset($hash[json_encode($sub)]);
}
// test
if (inHash($hash, array("d"=>1,"g"=>5,"c"=>16))) {
echo "found";
} else {
echo "not found";
}
Of course, if you could create the original immediately with such keys, then you don't have the overhead of creating it afterwards.