function trim_array($array){
$newarray= array();
$i = 0;
foreach ($array as $key => $value) {
if (!empty($value)) {
$newarray[$i] = $value;
$i++;
}
}
}
function trim_array_restorekey($array){
foreach ($array as $key => $value) {
if (empty($value)) {
unset($array[$key]);
}
}
return $array;
}
$sourseArray=array("0"=>"
"1"=>"blue",
"2"=>"",
"3"=>"green",
"4"=>"",
"5"=>"pink",
);
echo "Sourse array
";
print_r($sourseArray);
echo "
Remove Empty locations of array with out key restoration
";
print_r(trim_array($
echo "
Remove Empty locations of array with key restoration
";
print_r(trim_array_restorekey(
?>
output :
Source array
array("0"=>"Black",
"1"=>"blue",
"2"=>"",
"3"=>"green",
"4"=>"",
"5"=>"pink",
);
Remove Empty locations of array with out key restoration
array("0"=>"Black",
"1"=>"blue",
"2"=>"green",
"3"=>"pink",
);
Remove Empty locations of array with key restoration
array("0"=>"Black",
"1"=>"blue",
"3"=>"green",
"5"=>"pink",
);
[Wednesday, May 27, 2009
|
0
comments
]
Popular Posts
- MySQL stored procedure&triggers
- php questions
- Php Questions
- How we canmove into last changed position on info window close event On google map
- Pattern Matching in mysql
- MySQL INDEX
- MYSQL joins
- Jquery based dynamic adding and removal of html elements.
- securing a form with captcha
- Comparing a date with current date
0 comments
Post a Comment
Please put your comments here. your questions, your suggestions, also what went wrong with me.