Last active
May 7, 2017 05:08
-
-
Save palumbo/905a15cb574fb722fb71befb2b4439ca to your computer and use it in GitHub Desktop.
in_array example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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