php in array
snippet in php

php in array

user3544

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

in array php

user4752

<?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

user508

$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

javascript dedupe array

user7238

const names = ['John', 'Paul', 'George', 'Ringo', 'John'];

let x = (names) => names.filter((v,i) => names.indexOf(v) === i)
x(names); // 'John', 'Paul', 'George', 'Ringo'

in_array

user6754


<?php

$people = array("Peter", "Joe", "Glenn", "Cleveland");



if (in_array("Glenn", $people))

  {

  echo "Match found";

  }

else

  {

  echo "Match not found";

  }

?>