Hi
I need to search a multidimensional array (the result of an ldap_search query) for a possible value. If the value exists anywhere in the array, return true, else return false.
The function I have to search the array is;
function multiDimensionalArraySearch($searchValue, $arrayToSearch)
{
if (is_array($arrayToSearch)) {
for ($i=0; $i<count($arrayToSearch); $i++) {
// 1. If the result is another array, search within...
if (is_array($arrayToSearch[$i])) {
for ($ii=0; $ii<count($arrayToSearch[$i]); $ii++) {
// 2. 1. If the result is another array, search within...
if (is_array($arrayToSearch[$i][$ii])) {
for ($iii = 0; $iii < count($arrayToSearch[$i][$ii]); $iii++) {
// 3. 1. If the result is another array, search within...
if (is_array($arrayToSearch[$i][$ii][$iii])){
// end here
return false;
}
if ($arrayToSearch[$i][$ii][$iii] == $searchValue) {
return true;
}
}
}
// 1.1
if ($arrayToSearch[$i][$ii] == $searchValue) {
return true;
}
}
}
// 1.0
if ($arrayToSearch[$i] == $searchValue){
return true;
}
}
return false;
}
return false;
}
This means that if I call my function and pass it the array to search and a phrase to search on, I should get a true or false return...
My problem is;
Every time I pass a search which begins with 00 or 01 (zero zero OR zero one) it returns true even if the search phrase is non-existant - i.e, if the search phrase is 01username which in my case will be the value of another array, and I know that that value does not exist in the search array;
$phraseToSearchFor = $res[0]['uid']; // a result of ldap query - 01username
$arrayToSearchOn = $arr // a multidimensional array
if (multiDimensionalArraySearch($phraseToSearchFor, $arrayToSearchOn)) {
echo 'Result Found';
} else {
echo 'Result Not Found!';
}
The expected result would be Result Not Found!!, but I get Result Found.
If the phrase to search on has anything other than a 00 or 01 at the begining of it (say 02username or just username), everything works just fine?
Any ideas? Is my explenation clear?
Cheers
Steve