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...