Home > Backend Development > PHP Tutorial > //将数组中的元素是5的倍数的元素输出到下拉菜单 //将数组中的元素放在<li>标签中,奇偶li背景不同 //将数组中元素是数字型的找出来

//将数组中的元素是5的倍数的元素输出到下拉菜单 //将数组中的元素放在<li>标签中,奇偶li背景不同 //将数组中元素是数字型的找出来

WBOY
Release: 2016-06-23 13:32:42
Original
949 people have browsed it

求赐教

//将数组中的元素是5的倍数的元素输出到下拉菜单
//将数组中的元素放在

  • 标签中,奇偶li背景不同
    //将数组中元素是数字型的找出来


    回复讨论(解决方案)

    <?php //将数组中的元素是5的倍数的元素输出到下拉菜单$arr = array(1,2,3,5,15,25);$option = array_reduce($arr, function($r, $item){return $r.($item%5==0 ? "<option>".$item."</option>" : "");});echo "<select>$option</select>";//将数组中的元素放在<li>标签中,奇偶li背景不同$i = 0;$li = implode("", array_map(function ($n) use (&$i){$i++; return $i%2 == 0 ? "<li style='background-color:red;'>$n</li>" : "<li style='background-color:blue;'>$n</li>";}, $arr));echo "<ul>$li</ul>";//将数组中元素是数字型的找出来$arr = array(1,2,3,5,15,25, '12312','sdfsdf', 'asdasd123');$r = array_reduce($arr, function ($r, $item){is_null($r) && $r = array();return is_numeric($item) ? array_merge($r, array($item)) : $r; });print_r($r);?>
    Copy after login

  • 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