There are many ways to delete an array of empty elements. I will introduce two classic methods today. One is to use the array_filter function, and the other is to use the function to call a custom function.
The Code is as follows: |
Copy code |
<? Php $ Str1_array = array ('one-click tutorial net', '', 'HTTP: // www. bKjia. c0m','', '123 ',''); $ Str1_array = array_filter ($ str1_array ); Print_r ($ str1_array ); ?> Result Array ( [0] => yijucheng Http://www.bKjia. c0m [4] = & gt; 1654 )
|
Instance
The Code is as follows: |
Copy code |
$ FangId = PostGet ('houseid'); // get the address bar value $ TempArray = array_filter (explode ('_', $ fangId), "filter"); // divide the _ into arrays and delete empty arrays. If (is_array ($ tempArray )&&! Empty ($ tempArray) // checks whether the array has a value. { Print_r ($ tempArray); // test the output } Else { MessAge ('select compare real estate ', 'list. php '); } Function filter ($ var) Processing function { If ($ var = '') { Return false; } Return true; } |
Test method:/compare. php? HouseId = 2306425230742523031042308
For more details, see: http://www.bKjia. c0m/phper/21/b427d2b7535fc76ad744d41f825590dc.htm