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

Example of filtering odd and even numbers in php array

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-25 08:53:38
Original
1228 people have browsed it
  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);

复制代码


source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template