Re: Array elements missing
| From: | Jason Wong | Date: | Mon, 08 Apr 2002 18:42:30 +0000 |
| Subject: | Re: Array elements missing | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-92105@lists.php.net to get a copy of this message | ||
On Monday 08 April 2002 23:03, Joshua E Minnie wrote:
> Can anyone tell me why when the first element in my array would disappear
> with the following code:
>
> <?
> //remove the unwanted item from the array
> for($i=0;$i<count($stores);$i++) {
> $delete=0;
> //checking to see if it has been requested for delete
> foreach($HTTP_POST_VARS as $val) {
> if(is_numeric($val)) {
> if($val==$i) $delete = 1;
> else continue;
> }
> else continue;
> }
> //if not requested for delete, push on to temp array
> if($delete == 0) {
> array_push($temp, $stores[$i]);
> }
> }
> $stores = $temp;
> print_r($stores);
> print_r($HTTP_POST_VARS);
> ?>
I would rewrite the above as:
foreach ($HTTP_POST_VARS as $val) {
if(is_numeric($val)) {
unset($stores[$val]);
}
}
--
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
/*
Don't smoke the next cigarette. Repeat.
*/