Skip to content

Instantly share code, notes, and snippets.

@RobertAudi
Created July 21, 2010 15:14
Show Gist options
  • Save RobertAudi/484624 to your computer and use it in GitHub Desktop.
Save RobertAudi/484624 to your computer and use it in GitHub Desktop.
Return array keys that match the pattern.
<?php
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;
}
?>
@RobertAudi
Copy link
Author

Retrieved from this comment on the php preg_grep manual page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment