Answers for "check if an array contains a string php"

PHP
22

check if array has value php

$myArr = [38, 18, 10, 7, "15"];

echo in_array(10, $myArr); // TRUE
echo in_array(19, $myArr); // TRUE

// Without strict check
echo in_array("18", $myArr); // TRUE
// With strict check
echo in_array("18", $myArr, true); // FALSE
Posted by: Guest on January-21-2020
0

php if in array

$os = array("Mac", "NT", "Irix", "Linux");
if (in_array("Irix", $os)) {
    echo "Got Irix";
}
if (in_array("mac", $os)) {
    echo "Got mac";
}
Posted by: Guest on June-08-2021
0

php check if some string contains from array

$array = ["they has mystring in it", "some", "other", "elements"];
if (stripos(json_encode($array),'mystring') !== false) {
echo "found mystring";
}
Posted by: Guest on October-04-2021

Code answers related to "check if an array contains a string php"

Browse Popular Code Answers by Language