Trim and remove empty key & value in php array


Hits: 1454  

Here is the PHP function that will remove empty key => value in PHP array…

function array_trim($sv)
{
$s = 0;
$svn = null;
$c = count($sv);
for($i = 0; $i < $c; $i++)
{
if($sv[$i] != “”){
$svn[$s++] = trim($sv[$i]);
}
}
return $svn;
}

$svarray = array(‘   ‘, ‘svlinux’, ‘svnlabs’, ‘lamp’, ”);
$svarray = array_trim($svarray);
echo ‘<pre>’;
print_r($svarray);
echo ‘</pre>’;

Output:

Array(
[0] => svlinux
[1] => svnlabs
[2] => lamp
)