php数组过滤

  1. //fast filtering values of a array
  2. function fast_array_filter($array,$partten){
  3. $partten = '/' . preg_quote($partten) .'/';
  4. return preg_grep ($partten, $array);
  5. }
  6. //fast filtering keys of a array
  7. function fast_array_keys_filter($array,$partten){
  8. $partten = '/' . preg_quote($partten) .'/';
  9. $keys = preg_grep($partten,array_keys($array));
  10. //$retArray = array_combine ($keys , array_fill(0,count($keys),0) );
  11. $retArray = array_flip($keys)
  12. return array_intersect_key($array,$retArray);
  13. }

 

 

如过需要过滤除 空值 null 0 false 意外的任何值 fast_array_filter($array ,'/[^0]/');

你可能感兴趣的:(php数组)