I'm writing a function to loop through an array until a match is found based on another array. However the value is returning null.
My example:
$i = 1;
$tmp = ['fff'=>111,'aaa'=>100,'ddd'=>99,'ccc'=>87,'eee'=>45,'bbb'=>3,'ggg'=>1];
$prg = ['bbb','ccc'];
function doFilter($tmp,$prg,$i) {
$second = array_slice($tmp, $i, 1);
$snd = key($second);
if (!in_array(strtolower($snd),$prg)) {
$i++;
doFilter($tmp,$prg,$i);
} else {
// echo ccc
echo $snd;
return $snd;
}
}
$snd = doFilter($tmp,$prg,$i);
// echo NULL
echo $snd;
Any thoughts why the value within the function is not being returned to populate the variable as a response from the function?
$prgis in$tmpor you want to see all$prgthat are in$tmp?return doFilter($tmp,$prg,$i);array_intersect(array_keys($tmp), $prg)