preg_grep changed after php4.0.4+
| From: | alanjc45 at yahoo dot com | Date: | Sun, 04 Nov 2001 19:35:38 +0000 |
| Subject: | preg_grep changed after php4.0.4+ | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-73412@lists.php.net to get a copy of this message | ||
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