Common array functions in php (2) (array element filtering array_filter (), array array_filter

Source: Internet
Author: User

Common array functions in php (2) (array element filtering array_filter (), array array_filter

 

Array_filter ($ arr, 'filter _ func ');

// Parameter 1, array to be filtered

// Parameter 2: filtering function. If false is returned, this element is not added. true is returned to add this element.

 

Sample Code:

 

/*********** Array_filter (use the callback function to filter the elements in the array) * ***************/$ arr = array (); for ($ I = 0; $ I <10; $ I ++) {array_push ($ arr, $ I) ;}$ arrOdd = array_filter ($ arr, 'odd'); var_dump ($ arrOdd ); echo ' 

 

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.