Php array to delete an empty array program. 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 following code deletes 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: |
|
|
$ 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: |
|
|
$ 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
Bytes. The code is as follows...