Skip to content

Instantly share code, notes, and snippets.

@palumbo
Last active May 7, 2017 05:08
Show Gist options
  • Select an option

  • Save palumbo/905a15cb574fb722fb71befb2b4439ca to your computer and use it in GitHub Desktop.

Select an option

Save palumbo/905a15cb574fb722fb71befb2b4439ca to your computer and use it in GitHub Desktop.
in_array example
<?php $numbers = [8, 23, 15, 42, 16, 5]; ?>
<?php # is 15 in array?
$ans = in_array("15", $numbers);
if ($ans == 1) {
echo "true"; # returns true
} else {
echo "false";
};
?>
<?php # is 100 in array?
$answer = in_array("100", $numbers);
if ($answers == 1) {
echo "true";
} else {
echo "false"; # returns false
};
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment