PHP Filter Empty array method and filter array empty element filter empty array method I have three examples below, one is for,foreach,array_filter to handle, see the example below
PHP Tutorial Filter Empty array method and filter array to empty elements
Methods for filtering empty arrays I'm going to give you three examples, one for For,foreach,array_filter, and the example below.
*/
Method one uses Array_filter to invoke our custom function to filter the null value
function Clear ($a)
{
Return $a <> "";
}
$array = Array ("", ",", ",", ", 1,1,1,1,1);
$STT = Array_filter ($array, "clear");
Print_r ($STT);
/*
Output results
Array
(
[5] = 1
[6] = 1
[7] = 1
[8] = 1
[9] = 1
)
Null values are filtered
*/
Filter empty data Two, use loops to process
$array = Array ("", "', ' 2 '," ', ", 1,1,1,1,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 instance three, using for to instance
$tarray = Array (' ', ' one ', ', ' www.bkjia.com ', ' ', ' ', ' cn.net ');
$len = count ($tarray);
for ($i =0; $i < $len; $i + +)
{
if ($tarray [$i] = = ")
{
Unset ($tarray [$i]);
}
}
Print_r ($tarray);
/*
The result of filtering an empty array is
Array
(
[1] = 11
[3] = www.bkjia.com
[6] = Cn.net
)
Note: This site original tutorial to indicate the source www.bkjia.com
*/
http://www.bkjia.com/PHPjc/444942.html www.bkjia.com true http://www.bkjia.com/PHPjc/444942.html techarticle PHP Filter Empty array method and filter Array empty element filter empty array method I have three examples below, one is for,foreach,array_filter to deal with, see the example PHP tutorial over ...