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’, ‘phpsolutions’, ‘lamp’, ”);
$svarray = array_trim($svarray);
echo ‘<pre>’;
print_r($svarray);
echo ‘</pre>’;
Output:
Array(
[0] => svlinux
[1] => phpsolutions
[2] => lamp
)
2 Responses to Trim and remove empty key & value in php array
Leave a Reply
You must be logged in to post a comment.
Wow, that’s an incredibly nice read!
I am really thankful to the author with this post for producing this lovely and informative article live for us. We really appreciate ur effort. Maintain the favorable work. . . .