This article will share with you a function that uses php to create arrays to remove null values. It is very practical and recommended to you. I hope you will like it. 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.