PHP怎么查询数组中的指定元素

黄舟
Release: 2023-03-07 11:42:01
Original
3285 people have browsed it

array_search()函数在数组中搜索给定的值,找到后返回键值,否则返回 false 。在 PHP 4.2.0之前,函数在失败时返回 null 而不是 false。

语法格式如下

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

参数 needle 指定在数组中搜索的值;参数 haystack 指定被搜索的数组; 参数 strict 为可选参数,如果值为 true,还将数组中检查给定值的类型。

下面实例综合应用数组函数,实现更新数组中的元素的值,具体示例代码如下:



商品名称 价 格 数 量 金 额
Copy after login

运行结果为:

1435.png

上面的实例中,综合应用数组函数实现对数组中储存的商品数量进行修改,上图为运行结果!

说明:array_search()函数最常见的应用是购物车,实现对购物车中指定商品数量的修改和删除!

【相关教程推荐】

1. 相关专题推荐:《php数组(Array)



The above is the detailed content of PHP怎么查询数组中的指定元素. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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 [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!