This article mainly introduces PHP in the array to find the specified value of the method, the example analysis of PHP Array_search function to find the value of the array of the use of the skills, with a certain reference value, the need for friends can refer to the next
This example describes how PHP looks for a specified value in an array. Specific as follows:
PHP has two functions to determine whether the array contains the specified values, namely: Array_search ($value, $array) and In_array ($value, $array), Array_search can find out where the specified value appears in the array , the In_array function only determines if the specified value exists in the array and returns the BOOL value
<?php $array = Array ("Perl", "PHP", "Java", "PHP");p rint ("Search 1:". Array_search ("PHP", $array). " \ n ");p rint (" Search 2: ". Array_search (" Perl ", $array)." \ n ");p rint (" Search 3: ". Array_search (" C # ", $array)." \ n ");p rint (" \ n ");? >
The output is as follows
Search 1:1search 2:0search 3:
Summary : The above is the entire content of this article, I hope to be able to help you learn.