Trim and remove empty key & value in php array


Hits: 1487  

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
)

Published by

Sandeep Verma

I’m an Entrepreneur. I’m proud to work as Blogger, LAMP Programmer, Linux Admin, Web Consultant, Cloud Manager, Apps Developer, Searcher. Concentrate > Observe > Imagine > Launch

6 thoughts on “Trim and remove empty key & value in php array”

  1. Hey I know this is off topic but I was wondering if you knew
    of any widgets I could add to my blog that automatically tweet my newest twitter updates.
    I’ve been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something
    like this. Please let me know if you run into anything.
    I truly enjoy reading your blog and I look forward to your new updates.

  2. Howdy! I know this is somewhat off-topic but I had to ask.
    Does running a well-established blog such as yours require
    a lot of work? I am completely new to writing a blog however I
    do write in my diary everyday. I’d like to start a blog so I can easily share my experience and feelings online.
    Please let me know if you have any recommendations or tips
    for brand new aspiring bloggers. Appreciate it!

  3. I am really loving the theme/design of your blog. Do you ever run into any web browser compatibility issues?
    A small number of my blog visitors have complained about my
    blog not operating correctly in Explorer but looks great in Firefox.
    Do you have any recommendations to help fix
    this problem?

Leave a Reply

Your email address will not be published.

*