Re: select specified elements from an array
| From: | Gyozo Papp | Date: | Tue, 22 May 2001 22:27:04 +0000 |
| Subject: | Re: select specified elements from an array | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-53948@lists.php.net to get a copy of this message | ||
Thanks for your fast reply.
One more question related to this topic.
Would it be valueable to extend the existing array_values() function to support this feature?
just to balance with array_keys() and its optional value argument.
----- Original Message -----
From: "Markus Fischer" <mfischer@josefine.ben.tuwien.ac.at>
To: "Gyozo Papp" <pgerzson@freestart.hu>
Cc: <php-general@lists.php.net>
Sent: 2001. május 23. 00:14
Subject: Re: [PHP] select specified elements from an array
> On Wed, May 23, 2001 at 12:06:42AM +0200, Gyozo Papp wrote :
> > function array_part($fromarray, $keys)
> > {
> > foreach($fromarray as $key => $val)
> > {
> > if (in_array($key, $keys)
> > $anotherarray[$key] = $val;
> > }
> > return $anotherarray;
> > }
>
> foreach( $keys as $key)
> if( isset( $fromarray[ $key]))
> $anotherarray[ $key] = $fromarray[ $key];
>
> - Markus
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>