Re: Array elements missing
| From: | Joshua E Minnie | Date: | Tue, 09 Apr 2002 14:05:55 +0000 |
| Subject: | Re: Array elements missing | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-92233@lists.php.net to get a copy of this message | ||
Thanks for the suggestion. I did get it to work prior to your posting, but
this does help slim up my code quite a bit.
--
Joshua E Minnie
CIO
josh@acsurf.net
"Don't work for recognition, but always do work worthy of recognition."
"Jason Wong" <php-general@gremlins.com.hk> wrote:
> 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.
> */