in_array php
snippet in php

php in array

user1391

$colors = array("red", "blue", "green"); 
 
if (in_array("red", $colors)) { 
	echo "found red in array"; 
} 

in array php

user3483

<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");
if (in_array("Glenn", $people)){
	echo "Match found";
}
else{
	echo "Match not found";
}
?>

check if array has value php

user6929

$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

in_array php

user4572

<?php
$os = array("Apple", "Banana", "Lemon");
if (in_array("Apple", $os)) {
    echo "Yeah. Exist Apple";
}
if (!in_array("Buleberry", $os)) {
    echo "Oh, Don't Exist Blueberry!!!";
}
?>

php isarray

user4578


<?php
$yes = array('this', 'is', 'an array');

echo is_array($yes) ? 'Array' : 'not an Array';
echo "\n";

$no = 'this is a string';

echo is_array($no) ? 'Array' : 'not an Array';
?>

in_array php

user3730

<?php
$os = array("Mac", "NT", "Irix", "Linux");
if (in_array("Irix", $os)) {
    echo "Existe Irix";
}
if (in_array("mac", $os)) {
    echo "Existe mac";
}
?>