Re: preg_grep changed after php4.0.4+
| From: | Papp Gyozo | Date: | Sun, 04 Nov 2001 21:57:10 +0000 |
| Subject: | Re: preg_grep changed after php4.0.4+ | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-73418@lists.php.net to get a copy of this message | ||
It's documented (I've translated a week ago.)
<manual>
Since PHP 4.0.4, the results returned by preg_grep() are indexed using the
keys from the input array. If this behavior is undesirable, use
array_values() on the array returned by preg_grep() to reindex the values.
</manual>
----- Original Message -----
From: <alanjc45@yahoo.com>
To: <php-general@lists.php.net>
Sent: Sunday, November 04, 2001 8:35 PM
Subject: [PHP] preg_grep changed after php4.0.4+
> It does not appear to be in the documentation yet (and only a little
> blurb in the NEWS file)
> but preg_grep has changed.
>
>
> Assume $file_list is an array of file names using integer keys, e.g.,
> $file_list { 0 => "test", 1 => "filenames" }
> $result = preg_grep("/name/i", $file_list);
>
> Here is an example of what used to work:
> print_r($result) would print $result { 0 => "filenames" }
> So you could use $result[0] to get the value "filenames".
>
> They way it works now:
> print_r($result) prints $result { 1 => "filenames" }
> So you have to search $result for array_keys and then use the result of
> that on
> the original array.
> $keys = array_keys($result);
> and use $file_list[$keys[0]] to get the value "filenames"
> -or- create a for loop over $result -or- have the prescience to know the
> right key
> in $file_list to start with ;-)
>
> Is this documented somewhere? The current PHP manual on php.net & zend
> does
> not reflect this change. The change broke my script when I upgraded from
> 4.0.1...
> to 4.0.4+
>
> Documentation could well be the achilles heel of open source.
>
> -A
>
>
>
> --
> 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
>