Use PHP to select an even number in the array.

Source: Internet
Author: User

I have a small algorithm that selects all the even or the technology in the array. A lot of people may, would loop this array, and I just do not loop the array can do this, the code is as follows.

function Odd ($var) {    //returns whether the input integer is odd    return ($var & 1);} function even ($var) {    //returns whether the input integer is even    return (! ( $var & 1));} $array 1 = Array ("A" =>1, "B" =>2, "C" =>3, "D" =>4, "E" =>5), $array 2 = Array (6, 7, 8, 9, ten, one,); echo "ODD: \ n ";p rint_r (Array_filter ($array 1," odd ")), echo" even:\n ";p Rint_r (Array_filter ($array 2," even "));

Use PHP to select an even number in the array.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.