Home  >  Article  >  Backend Development  >  How to query specified elements in an array in PHP

How to query specified elements in an array in PHP

黄舟
黄舟Original
2017-05-04 10:41:253294browse

The array_search() function searches for a given value in the array and returns the key value if found, otherwise it returns false. Prior to PHP 4.2.0, functions returned null instead of false on failure.

The syntax is as follows

mixed aarray_search(mixed needle,array haystack [,bool strict])

The parameter needle specifies the value to be searched in the array; the parameter haystack specifies the array to be searched; the parameter strict is an optional parameter. If the value is true, it will also be included in the array. Checks the type of a given value.

The following example comprehensively applies array functions to update the values ​​of elements in the array. The specific example code is as follows:



商品名称 价 格 数 量 金 额

The running result is:

How to query specified elements in an array in PHP

In the above example, the array function is comprehensively applied to modify the number of commodities stored in the array. The above picture is the running result!

Description: The most common application of the array_search() function is the shopping cart, which allows you to modify and delete the specified number of items in the shopping cart!

【Related tutorial recommendations】

1. Relevant topic recommendations: "php array (Array)



The above is the detailed content of How to query specified elements in an array in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn