PHP function in_array () how to check the value in the array _ PHP Tutorial

Source: Internet
Author: User
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 ().

 
 
  1. <? $NamesArray=Array("Heart", "Love", "Boy", "Mary", "Paul", "Merry", "Jacky ");
  2. $LookingFor="Albert";
  3. If (in_array ($ lookingFor, $ namesArray )){
  4. Echo "found! ";
  5. } Else {
  6. Echo "you cannot find the value in the array! ";
  7. }
  8. ?>

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 「...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.