Php array-delete an empty array Program

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.