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

To check if a specific value exists in an array in PHP, you can use the in_array() function. The in_array() function searches for a specific value in an array and returns true if found, and false otherwise. Here is an example:

$array = [1, 2, 3, 4, 5]; if (in_array(3, $array)) { echo "Value exists in the array"; } else { echo "Value does not exist in the array"; }

In this example, the in_array() function checks if the value 3 exists in the $array. If it does, it will output "Value exists in the array", otherwise, it will output "Value does not exist in the array".