PHP array_filter() 函数
PHP 教程
· 2019-01-22 07:59:39
实例
用回调函数过滤数组中的元素:
function test_odd($var)
{
return($var & 1);
}
$a1=array("a","b",2,3,4);
print_r(array_filter($a1,"test_odd"));
定义和用法
array_filter() 函数用回调函数过滤数组中的元素。
该函数把输入数组中的每个键值传给回调函数。如果回调函数返回 true,则把输入数组中的当前键值返回给结果数组。数组键名保持不变。
语法
array array_filter ( array $array [, callable $callback [, int $flag = 0 ]] )
| 参数 | 描述 |
|---|---|
| array | 必需。规定要过滤的数组。 |
| callback | 可选。规定要用的回调函数。 |
| flag | 可选。决定 callback 接收的参数形式:
|
技术细节
| 返回值: | 返回过滤的数组。 |
|---|---|
| PHP 版本: | 4.0.6+ |
点击查看所有 PHP 教程 文章: https://www.codercto.com/courses/l/5.html
HTTP Essentials
Stephen A. Thomas、Stephen Thomas / Wiley / 2001-03-08 / USD 34.99
The first complete reference guide to the essential Web protocol As applications and services converge and Web technologies not only assume HTTP but require developers to manipulate it, it is be......一起来看看 《HTTP Essentials》 这本书的介绍吧!