Use php to select an even number in the array

Source: Internet
Author: User
Use php to select an even number in the array. I have such a small algorithm that selects all the even numbers or technologies in the array. Many people may loop through this array, but I can do this without repeating the array. 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) ;}$ array1 = array ("a" => 1, "B" => 2, "c" => 3, "d" => 4, "e" => 5); $ array2 = array (6, 7, 8, 9, 10, 11, 12); echo "Odd: \ n "; print_r (array_filter ($ array1," odd "); echo" Even: \ n "; print_r (array_filter ($ array2," even "));

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.