array_search()函数在数组中搜索给定的值,找到后返回键值,否则返回 false 。在 PHP 4.2.0之前,函数在失败时返回 null 而不是 false。
语法格式如下
mixed aarray_search(mixed needle,array haystack [,bool strict])
参数 needle 指定在数组中搜索的值;参数 haystack 指定被搜索的数组; 参数 strict 为可选参数,如果值为 true,还将数组中检查给定值的类型。
下面实例综合应用数组函数,实现更新数组中的元素的值,具体示例代码如下:
商品名称 | 价 格 | 数 量 | 金 额 |
运行结果为:
上面的实例中,综合应用数组函数实现对数组中储存的商品数量进行修改,上图为运行结果!
说明: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!