Blogger Information
Blog 34
fans 0
comment 0
visits 20284
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php 求数组中的偶数成员
小庄
Original
594 people have browsed it

  1. <?php
  2. /**
  3. * 1.// 给定一个数组$arr = [23,3,45,6,78,8,34],筛选其偶数成员组成新的数组返回,请封装函数。
  4. */
  5. // 筛选
  6. $arr = [23,3,45,6,78,8,34];
  7. function getDouble($arr){
  8. $arrDouble = [];
  9. $j = 0;//下标
  10. for($i = 0;$i < count($arr);$i++){
  11. if($arr[$i] % 2 == 0){
  12. $arrDouble[$j] = $arr[$i];
  13. $j++;
  14. }
  15. }
  16. return $arrDouble;
  17. }
  18. // 调用
  19. $z = getDouble($arr);
  20. // 打印帅选出来的值
  21. for($i = 0;$i < count(getDouble($arr)); $i++){
  22. echo $z[$i]."<br />";
  23. }
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!