// Method 1 use array_filter to call our custom function to filter null values
The code is as follows: |
Copy code |
Function clear ($) { Return $ a <> ""; } $ Array = array ("", '', 1 ); $ Stt = array_filter ($ array, "clear "); |
Print_r ($ stt );
/*
Output result
Array
(
[5] => 1
[6] => 1
[7] => 1
[8] => 1
[9] => 1
)
Null value filtered
*/
// Filter empty data and process it cyclically
The code is as follows: |
Copy code |
$ Array = array ("", '', '2','', '', 1 ); Foreach ($ array as $ v => $ vc) { If ($ vc = '') { Unset ($ array [$ v]); } } Print _ |
R ($ array );
/*
Array
(
[2] => 2
[5] => 1
[6] => 1
[7] => 1
[8] => 1
[9] => 1
)
*/
// Method Example 3: Use for instance
The code is as follows: |
Copy code |
$ Tarray = array ('', '11','', 'www .111cn.net ', '','', 'CN. Net '); $ Len = count ($ tarray ); For ($ I = 0; $ I <$ len; $ I ++) { If ($ tarray [$ I] = '') { Unset ($ tarray [$ I]); } } Print_r ($ tarray ); |
/*
The result after filtering the empty array is
Array
(
[1] => 11
[3] => www.111cn.net
[6] => cn.net
)
Note: The Original tutorial on this site will indicate the source www.111cn.net
*/