Yes, I tested my code. I am sorry, I had just added in the else statement for this post, as I have it working correctly as this:
function array_search_partial($arr, $keyword) {
foreach ($arr as $index => $string) {
$userBase = basename($string);
$test = substr_count($userBase, '-');
if($test === 2) {
if(preg_split("/[-]+/", $userBase)[2] == $keyword) {
return $index;
}
}
}
}
It only needs to find one item, as the $keyword is a unique identifier. But you are right I should return false to the caller. Which is :
$index = array_search_partial($profilePaths, $userName);
if($index){
$profileLink = "/".$profilePaths[$index].".html";
}