Q:

How to check if a value exists in an array in PHP

0

How to check if a value exists in an array in PHP

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Use the PHP in_array() function

You can use the PHP in_array() function to test whether a value exists in an array or not.

Let's take a look at an example to understand how it basically works:

<?php
$zoo = array("Lion", "Elephant", "Tiger", "Zebra", "Rhino", "Bear");
if(in_array("Elephant", $zoo)){
    echo "The elephant was found in the zoo.";
}
echo "<br>";
if(in_array("Tiger", $zoo)){
    echo "The tiger was found in the zoo.";
}
?>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now