From: dkadosh at affinegy dot com Operating system: any PHP version: 5.3.20 Package: PCRE related Bug Type: Feature/Change Request Bug description:Need option to search in array keys instead of values
Description: ------------ --- >From manual page: http://www.php.net/function.preg-grep --- I'm asking for an extra flag to this function, to cause it to do its search in the array keys rather than in the values. While there's a comment in the above page of how to "post-process" preg_grep() results to achieve this, I'd rather it be done in C (inside the PCRE code) than PHP for performance reasons. I thought about something like this: $a = array_flip( preg_grep('/Version$/', array_flip($aParams)) ); which would almost return what I want, HOWEVER it has two problems: 1) If certain values of $aParams are duplicated, the first array_flip() will "lose" those rows in the array. 2) I'd incur a sizeable CPU and memory hit by calling array_flip, which duplicates the array(s) in RAM. Test script: --------------- The current work-around: function preg_grep_keys( $pattern, $input, $flags = 0 ) { $keys = preg_grep( $pattern, array_keys( $input ), $flags ); $vals = array(); foreach ( $keys as $key ) { $vals[$key] = $input[$key]; } return $vals; } -- Edit bug report at https://bugs.php.net/bug.php?id=63818&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=63818&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=63818&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=63818&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=63818&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=63818&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=63818&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=63818&r=needscript Try newer version: https://bugs.php.net/fix.php?id=63818&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=63818&r=support Expected behavior: https://bugs.php.net/fix.php?id=63818&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=63818&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=63818&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=63818&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=63818&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=63818&r=dst IIS Stability: https://bugs.php.net/fix.php?id=63818&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=63818&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=63818&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=63818&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=63818&r=mysqlcfg