PHP array deletion empty array program_PHP tutorial

WBOY
Release: 2016-07-13 10:55:27
Original
1061 people have browsed it

There are many array methods for deleting empty elements. Today I will introduce two classic methods. One uses the array_filter function, and the other also uses the function to call a custom function.

( [0] => Yiju Tutorial Network
The code is as follows
 代码如下 复制代码

$str1_array=array('一聚教程网','','http://www.bKjia.c0m','','1654','');
$str1_array=array_filter($str1_array);
print_r($str1_array);
?>

结果


Array
(
[0] => 一聚教程网
[2] => http://www.bKjia.c0m
[4] => 1654
)

Copy code


$str1_array=array('Yiju Tutorial Network','','http://www.bKjia.c0m','','1654','');

$str1_array=array_filter($str1_array);
代码如下 复制代码

$fangId = PostGet('houseId'); // 取得地址栏值
$tempArray = array_filter(explode('_',$fangId),"filter"); //以__分成数组并且删除空数组

if( is_array($tempArray) && !empty( $tempArray ) ) //判断数组是否有值
{
print_r($tempArray); //测试输出
}
else
{
MessAge('请选择对比较楼盘','list.php');
}

function filter($var) 处理函数
{
if($var == '')
{
return false;
}
return true;
}

print_r($str1_array);

?>
Results


Array
[2] => http://www.bKjia.c0m [4] => 1654

)

Example
The code is as follows Copy code
$fangId = PostGet('houseId'); // Get the address bar value $tempArray = array_filter(explode('_',$fangId),"filter"); //Divide into arrays with __ and delete empty arrays if( is_array($tempArray) && !empty( $tempArray ) ) //Determine whether the array has a value
{
print_r($tempArray); //Test output } else { MessAge('Please select the property to compare','list.php'); } function filter($var) processing function { if($var == '') { Return false; } Return true; } Test method:/compare.php?houseId=2306__2307__2303__2308 For more details, please see: http://www.bKjia.c0m/phper/21/b427d2b7535fc76ad744d41f825590dc.htm http://www.bkjia.com/PHPjc/632255.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632255.htmlTechArticleThere are many array methods to delete empty elements. Today I will introduce two classic methods. One is to use array_filter function, and the other also uses functions to call custom functions. The code is as follows...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!