Home » » Remove empty elements from php array

Remove empty elements from php array

Written By Unknown on Kamis, 28 April 2011 | 02.45

Want to get rid of empty elements from an array. Use this function. Just pass the array to the function. It will return resultant array without empty elements.

  function remove_empty($array) {
foreach($array as $key => $value){
if(trim($value) == ''){
unset($array[$key]);
}
}
return $array;
}


Call function like this

$result = remove_empty($array);
print_r($result);
Share this article :

Posting Komentar

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Kumpulan Kata Broadcast Blackberry - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger