Posted By

iloveitaly on 07/16/10


Tagged

search array key associative


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

postNuKe
osirisinternet


Array Search on Key


 / Published in: PHP
 

like array_search but compares against a specific key in each element of the array

  1. function array_search_key($needle, $haystack, $haystackKey, $strict = false) {
  2. foreach($haystack as $key => $value) {
  3. if(isset($value[$haystackKey])) {
  4. if($strict) {
  5. if($value[$haystackKey] === $needle) return true;
  6. } else {
  7. if($value[$haystackKey] == $needle) return true;
  8. }
  9. }
  10. }
  11.  
  12. return false;
  13. }

Report this snippet  

You need to login to post a comment.