How to check if a value exists in an array in PHP
In this post we will give you information about How to check if a value exists in an array in PHP. Hear we will give you detail about How to check if a value exists in an array in PHPAnd how to use it also give you demo for it if it is necessary.
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.";
}
?>
i hope you like this article.
Hope this code and post will helped you for implement How to check if a value exists in an array in PHP. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs