PHP search and search for array elements

Source: Internet
Author: User
This article mainly introduces the PHP search and search for array elements. The example summarizes the usage techniques of function operation arrays such as in_array, array_key_exists, array_search, array_keys, and array_values in php, for more information about how to search for array elements in PHP, see the following example. Share it with you for your reference. The specific analysis is as follows:

Searching, filtering, and searching array elements are common functions of array operations. The following describes several related functions.

In_array () function

The in_array () function searches for a specific value in an array. if this value is found, true is returned. otherwise, false is returned. The format is as follows:

The code is as follows:

Apple's color is red

Array_search () function

The array_search () function searches for a specified value in an array. If yes, the corresponding key is returned. otherwise, false is returned. The format is as follows:

The code is as follows:

Watermelon was founded on green.

Array_keys () function

The array_keys () function returns an array containing all the keys found in the searched array. The format is as follows:

The code is as follows:

Array ([0] => apple [1] => banana [2] => watermelon)

Array_values () function

The array_values () function returns all values in an array and automatically provides a numerical index for the returned array. The format is as follows:

The code is as follows:

Array ([0] => red [1] => yellow [2] => green)

I hope this article will help you with php programming.

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.