How does the PHP function in_array () check the values in the array. The program learning the following example will display the "Notfoundinthisarray" string on the page, because the string you are looking for is "learningThe program in the following example will display the string "you cannot find the value in the array" ("Not found in this array") on the page, because the string Albert you are looking for is indeed not in the $ namesArray array:
The following describes how to use the PHP function in_array ().
- <? $NamesArray=Array("Heart", "Love", "Boy", "Mary", "Paul", "Merry", "Jacky ");
-
- $LookingFor="Albert";
-
- If (in_array ($ lookingFor, $ namesArray )){
-
- Echo "found! ";
-
- } Else {
-
- Echo "you cannot find the value in the array! ";
-
- }
-
- ?>
If you change the value of $ lookingFor to "Mary" and execute the command again, "found" will be displayed on this screen !」 ("You 've got it! "), Because the" Mary "value does exist in the $ namesArray array. If you want to know the total number of elements contained in an array, you can use the easy-to-use count () function:
The value of the variable $ count is 7.
The above is the specific application method of the PHP function in_array.
The program in the example below will display the "the value you are looking for cannot be found in the array" ("Not found in this array") string on the page, because the string you are looking 「...