时间:2021-12-16 09:50:43 | 栏目:PHP代码 | 点击:次
1、array_filter() 函数可以用回调函数来过滤数组中的元素,将数组元素传递给回调函数进行处理。
2、如果回调函数返回true,则把输入数组中的当前键值返回给结果数组。
(数组键名保持不变)
<?php $array = array("php", 11, '', 12, "脚本之家",13,"green",2021,"mysql","14",15); function filter_number($value){ if(is_numeric($value)){ return TRUE; } } $result=array_filter($array,"filter_number"); var_dump($result); ?>
知识点扩展:
用array_merge和加号来何必这两数组
<?php print_r($r+e); // 输出<span style="font-family: Simsun;font-size:16px; ">Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 ) </span> print "<br />"; print_r(array_merge($r,$e)); // 输出<span style="font-family: Simsun;font-size:16px; ">Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 [8] => 9 )</span> ?>