php method to determine whether an array has a certain element: 1. Create a new php file and create an array; 2. Use the "in_array" function to determine whether there is a specified element in the array "$arr"; 3. Just output the judgment result.
The operating environment of this tutorial: windows10 system, PHP8.1 version, DELL G3 computer
How does php determine whether an array contains a certain indivual?
PHP checks whether the specified element exists in an array
Create a new php file, named test.php, to explain how PHP checks an array Whether the specified element exists.
In the Zhutai test.php file, use the header() method to set the encoding format of the page to utf-8 to avoid outputting Chinese garbled characters.
In the test.php file, create an array for testing.
In the test.php file, use the in_array function to determine whether there is a bb element in the array $arr. If so, return true.
In the test.php file, use the if statement to determine the result of the previous step and output a prompt.
Open the test.php file in the browser to view the results.
Recommended study: "PHP Video Tutorial"
The above is the detailed content of How to determine whether an array contains an element in php. For more information, please follow other related articles on the PHP Chinese website!