PHP sometimes needs to determine whether a certain value exists in an array. We can directly use the PHP built-in function in_array() to realize the determination. The php in_array function is used to check whether a certain value exists in the array. If it exists, it returns true, otherwise it returns false. This article introduces the basic syntax and usage examples of the in_array function. Interested friends can refer to it.
php in_array() Check whether a certain value exists in the array
in_array Check whether a certain value exists in the array
Basic syntax :
bool in_array(mixed $needle,array $haystack,bool $strict=FALSE)
Search needle
in haystackParameter introduction
Parameter | Description |
---|---|
needle | Required. Specifies the value to search for in the array. If it is a string, the comparison is case-sensitive. |
haystack | Required. Specifies the array to search. |
strict | Optional. If this parameter is set to true, the in_array() function also checks whether the type of needle is the same as that in haystack. |
Return value
Returns TRUE if needle is found, otherwise returns FALSE.
Example:
The second condition of running online fails because in_array() is case-sensitive, so the above program is displayed as :
Got Irix
The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:
phpImplement uploading excel tables and obtain data
PHP’s method of implementing regular regular verification helper public class
PHP’s method of implementing web content html tag completion and filtering
The above is the detailed content of Detailed explanation of php in_array() checking whether a certain value exists in the array. For more information, please follow other related articles on the PHP Chinese website!