fork(9) download
  1. <?php
  2.  
  3. function preg_grep_keys_values($pattern, $input, $flags = 0) {
  4. return array_merge(array_intersect_key($input, array_flip(preg_grep($pattern, array_keys($input), $flags))),
  5. preg_grep($pattern, $input, $flags));
  6. }
  7.  
  8. $a = array(
  9. 'mark@test.by.com'=> "Mark Mian lv",
  10. 'jhon@test.lv.com'=> "John jack lv",
  11. 'logon@test.en.com'=> "Bob Logon",
  12. 'Stela@test.es.com'=> "Stela Josh",
  13. 'json@test.es.com'=> "Json Josh",
  14. 'bobby@test.lv.com'=> "Bob Mark"
  15. );
  16.  
  17. $r = preg_grep_keys_values('~lv~i', $a);
  18. print_r($r);
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
Array
(
    [jhon@test.lv.com] => John jack lv
    [bobby@test.lv.com] => Bob Mark
    [mark@test.by.com] => Mark Mian lv
)