To Remove An Empty Element From An Array Using PHP

This Tutorial Has Been Viewed 586 Times.

Guys in the below code i am explaining how you can find out the

empty array…and create a new array by deleting the empy ones

dynamically.

In the variable data array i have given 8 datas

let $a, $b, $c, $d,$e contains data and others that is $f, $g, $h are empty so we will get the new array size as 5 by using the

sizeof() in PHP.

$data=array(“$a”, “$b”, “$c”, “$d”, “$e” , “$f” ,”$g” , “$h”);
//print_r($data);
function array_trim($data)
{
$j = 0;
for ($i = 0; $i < count($data); $i++)
{ if ($data[$i] != “”)
{ $b[$j++] = $data[$i];
}
}
return $b;
}

$new_size=array_trim($data);

VN:F [1.9.13_1145]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.13_1145]
Rating: 0 (from 0 votes)

Incoming search terms:





You will also be interested in ,

Tags: ,

One Response

  1. samarubanok says:

    good..

    VA:F [1.9.13_1145]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.13_1145]
    Rating: 0 (from 0 votes)

Leave a Reply

Spam protection by WP Captcha-Free

Proudly designed by Mistonline.in.
Affordable Seo PackagesSeo BlogEdu Backlinks
More in PHP (119 of 122 articles)