fork download
  1. <?php
  2.  
  3. $myArray = ['knitting needle', 'haystack', 'needlepoint'];
  4.  
  5. $search = 'needle';
  6. $keys = array_keys(
  7. $myArray,
  8. function ($value) use ($search) {
  9. return (strpos($value, $search) !== false);
  10. }
  11. )
  12. );
  13.  
  14. var_dump($keys);
  15.  
Success #stdin #stdout 0.02s 24400KB
stdin
Standard input is empty
stdout
array(2) {
  [0]=>
  int(0)
  [1]=>
  int(2)
}