Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php array_search single array with multiple hits

Tags:

arrays

php

I'm doing a calendar with possibly more than 1 event matching the date each day. Currently I'm puzzled as how to discover more than the first match with array_search. Here is what I'm doing right now.

if (array_search($date_today, $event_start) !== FALSE ) {
     $date_match = array_search($date_today, $event_start);
     $name       = $event_name[$date_match];    
   }

Can I advance the array_search with a 'while' or 'for each' statement to find multiple matches? In case it's important my date variables are dates like 1368680400.

like image 461
Maelish Avatar asked Apr 05 '13 19:04

Maelish


1 Answers

Documentation for array_search tells us:

If needle is found in haystack more than once, the first matching key is returned. To return the keys for all matching values, use array_keys() with the optional search_value parameter instead.

like image 118
barbashov Avatar answered Sep 27 '22 22:09

barbashov