Re: [PHP4BETA] howto remove key/value from array based on regexp
| From: | Ly) Vuong | Date: | Tue, 11 Apr 2000 15:33:49 +0000 |
| Subject: | Re: [PHP4BETA] howto remove key/value from array based on regexp | ||
| References: | 1 2 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-13387@lists.php.net to get a copy of this message | ||
I believe unset() will affect the array's internal pointer. So, it's
better to use list(..) and each(..). I would do something similar to
this:
while(list($k, $v) = each($arry))
{
if(!strcmp(trim($v),""))
unset($arry[$k]);
}
Cheers,
Ly
---
teo@digiro.net wrote:
>
> Hi Dan!
> On Tue, 11 Apr 2000, Dan Larsson wrote:
>
> > My aim is to remove any keys where the values contain nothing but
> > spaces and/or newlines from an array.
> >
> > $array[0] = '123';
> > $array[1] = ' ';
> > $array[2] = 'abc';
> >
> > so that the above array becomes
> >
> > $array[0] = '123';
> > $array[1] = 'abc';
> >
> > Any ideas?
> I was hopping one of the new arr. functions can help you.
> Else try smth. like:
> foreach ($array as $k => $v)
> (trim($v) == '') && unset ($array ($k));
>
> I'm not sure unset()-ing doesn't screw up internal array pointer
> or something.[e.g. untested]
>
> -- teodor
>
> --
> PHP 4.0 Beta Mailing List <http://www.php.net/version4/>
> To unsubscribe, e-mail: php4beta-unsubscribe@lists.php.net
> For additional commands, e-mail: php4beta-help@lists.php.net
> To contact the list administrators, e-mail: php4beta-admin@lists.php.net