84669 Lernen von Personen
152542 Lernen von Personen
20005 Lernen von Personen
5487 Lernen von Personen
7821 Lernen von Personen
359900 Lernen von Personen
3350 Lernen von Personen
180660 Lernen von Personen
48569 Lernen von Personen
18603 Lernen von Personen
40936 Lernen von Personen
1549 Lernen von Personen
1183 Lernen von Personen
32909 Lernen von Personen
比如 uasort($arr ,"myRegExp") 和 array_filter($arr,"myGt")
我要是想对 myRegExp 或者 myGt 传值的时候怎么弄?
比如这个 myGt 是个小于 88的函数:
function myGt($val) { if ($val >= 88) return true; }
能不能把这个88也写到 array_filter 的参数里?
小伙看你根骨奇佳,潜力无限,来学PHP伐。
何不尝试自己封装array_filter
function user_array_filter($array = array(), $callback = null) { $args = func_get_args(); if( count($args) < 2 ) { exit('Missing arguments for user_array_filter, two arguments at least'); } if( count($args) == 2 ) { foreach( $array as $k => $v ) { $result = $callback($v); if( !$result ) { return false; } } } else { $limit = $args[2]; foreach( $array as $k => $v ) { $result = $callback($v, $limit); if( !$result ) { return false; } } } return true; } function myGt($val, $limit = 88){ if ($val >= $limit) return true; return false; }
自己写一个函数
function filter_by_value ($array, $min) { if(is_array($array) && count($array)>0) { foreach($array as $key => $value) { if($value > $min) { $newarray[$key] = $value; } } } return $newarray; } $arr = [10,78,91,101,410,7,36]; print_r(filter_by_value($arr,88));
你看下函数手册http://php.net/manual/zh/func...
自定义数组过滤
何不尝试自己封装array_filter
自己写一个函数
你看下函数手册
http://php.net/manual/zh/func...
自定义数组过滤