Home  >  Article  >  Backend Development  >  Example of filtering odd and even numbers in php array

Example of filtering odd and even numbers in php array

WBOY
WBOYOriginal
2016-07-25 08:53:381145browse
  1. function pick_one_side($arr, $need_odd){

  2. return array_filter($arr, function($item) use($need_odd){
  3. return $need_odd ? ($item & 1) : (!($item & 1));
  4. });
  5. }

  6. //数据筛选调用

  7. $one_side = pick_one_side(range(1, 100), false);
  8. print_r($one_side);

复制代码


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn