How to check if string is in array with php? How to check if string is in array with php? arrays arrays

How to check if string is in array with php?


foreach ($array as $subarray){   if(!in_array('hello', $subarray))   {      echo 'echo the value';   }}


For multi-dimensional array, try:

function in_array_r($needle, $haystack, $strict = true) {    foreach ($haystack as $item) {        if (($strict ? $item === $needle : $item == $needle) || (is_array($item) && in_array_r($needle, $item, $strict))) {            return true;        }    }    return false;}


$attendance = ['present','absent','present','present','present','present'];if (in_array("absent", $attendance)){     echo "student is failed";  } else {           echo "student is passed";       }