How can i take the array below and remove the empty values and then reorder the array?
Array ( [0] => 20 [1] => [2] => [3] => [4] => [5] => 40 [6] => [7] => [8] => [9] => )
So this would then become [0]=> 20 , [1] => 40
Thank you in advance.
urgent help with arrays
Moderator: General Moderators
- DaveTheAve
- Forum Contributor
- Posts: 385
- Joined: Tue Oct 03, 2006 2:25 pm
- Location: 127.0.0.1
- Contact:
Re: urgent help with arrays
Code: Select all
$tmp = array();
foreach($array as $key=>$value) {
if (!empty($key)) {
$tmp[] = $value;
}
}
$array = $tmp;
unset($tmp);
Re: urgent help with arrays
Yes this work thanks. One thing though
$tmp = array();
foreach($array as $key=>$value) {
if (!empty($key)) {
$tmp[] = $value;
}
it should be !empty $value;
$tmp = array();
foreach($array as $key=>$value) {
if (!empty($key)) {
$tmp[] = $value;
}
it should be !empty $value;