So say I have the following array:
array(
'key1'=>array(
'key.1'=>'tester',
'key.2'=>'tester'
),
'key2'=>array(
'key.1'=>'failedtester',
'key.2'=>'tester'
)
)
How do I search this array such that I return back the parent keys such that a value is a certain value based off a sub key?
e.g. Return the keys such that key.1 == tester (this would return key1)
e.g. Return the keys such that key.1 == failedtester (this would return key2)
e.g. Return the keys such that key.2 == tester (this would return array(key1, key2)
Is this possible without doing a for loop?
Edit: Using PHP (sorry thought I had said PHP, apparently not.. #fail)
Solution 1: two nested loops, total time complexity is O(n*n):
Solution 2: the inner loop is replaced by a lookup, total complexity is O(n*log(n)). This should be significantly faster for large n: