<?php
$sections = ['test', 'nesto', 'fo', 'bar', ['obama', 'tito']];
function search($sections, $query){
$found = false;
foreach ($sections as $section){
if ($section == $query){
$found = true;
var_dump($found);
return $found;
}
if (is_array($section)){
search($section, $query);
}
}
var_dump($found);
return $found;
}
if (search($sections, 'obama')){
echo 'search item found';
}else{
echo 'nothing found';
}
I wrote a simplified version of my problem. Basically I am trying to find a value inside an nested array. I get the following output: bool(true) bool(false) nothing found. Why does found value change from true to false. Why doesn't the function terminate when $section == $query ?