Php array function sharing, php array function sharing _ PHP Tutorial

Source: Internet
Author: User
Share functions with php array to remove null values, and share php array functions. The php array removes null values. The php array function shares how to clear null elements in a one-dimensional php array? The direct method is to loop through the foreach, share the null values of php arrays, and share the php array functions.

For a one-dimensional php array, how does one clear elements with null values? The direct method is to loop through foreach and judge and exclude them one by one. However, this method is a little complicated. let's share one of the methods we can see today, which is very simple.

The code is as follows:


/**
* Empty library-array removal of null values
* @ Param string $ num value
* @ Return string
*/
Public function array_remove_empty (& $ arr, $ trim = true ){
If (! Is_array ($ arr) return false;
Foreach ($ arr as $ key => $ value ){
If (is_array ($ value )){
Self: array_remove_empty ($ arr [$ key]);
} Else {
$ Value = ($ trim = true )? Trim ($ value): $ value;
If ($ value = ""){
Unset ($ arr [$ key]);
} Else {
$ Arr [$ key] = $ value;
}
}
}
}

Is it a very practical function? I hope everyone will like it.

For a one-dimensional php array, how does one clear elements with null values? The direct method is to loop through the foreach, one by one...

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.