I have an array, inside an array. I'd like to search the values in that nestled array.
Currently I'm trying:
foreach ($retval as $k => $v) {
if (is_array($v)) {
$search = array_search($group_name, $v);
}
}
if ($search == FALSE) {
// Nothing was found
} else {
// results found
}
Once this has been done, I simply want to perform an action depending on whether a result was found or not in the search.
How do you do this?
You need to change $search = array_search($group_name,$v);
to:
$search = false;
foreach($retval as $k=>$v){
if(array_search($group_name,$v)){
$search = true;
}
}
Basically, you only want to assign true to search if you found the value you are looking for. Otherwise you could overwrite search's value with false. For example, say search is in element 0, you set it to true. Then in element 1 the element is not there, you then set search to false.
Furthermore, if you only care about knowing it's there, you could add break;
after $search = true;
to stop searching the array.