Home > Mobile >  if in array doesn't find value
if in array doesn't find value

Time:02-27

I tried this to find the value "Einkauf" in my array:

for ($i = 0; $i < count($myArray['category']); $i  ) {
   echo $myArray['category'][$i]['name'].'<br />'; // Debug

   if (in_array("Einkauf", $myArray['category'][$i]['name'])) {
      echo "Yes!";
      break;
   }
}

My "Debug" line gives this output:

Verwaltung
Personal
Einkauf

As you can see, the value "Einkauf" exist. But I get no echo "Yes!";

Any idea? :)

CodePudding user response:

in_array doesn't work in this case, try this

for ($i = 0; $i < count($myArray['category']); $i  ) {
   echo $myArray['category'][$i]['name'].'<br />'; // Debug

   if ("Einkauf" === $myArray['category'][$i]['name'])) {
      echo "Yes!";
      break;
   }

}

  • Related