我正在做一个日历,每天可能有超过 1 个事件与日期匹配。目前我很困惑如何发现比 array_search 的第一个匹配项更多的内容。这是我现在正在做的事情。
if (array_search($date_today, $event_start) !== FALSE ) {
$date_match = array_search($date_today, $event_start);
$name = $event_name[$date_match];
}
我能否使用“while”或“for each”语句推进 array_search 以查找多个匹配项?如果它很重要,我的日期变量是像 1368680400 这样的日期。
最佳答案
Documentation for array_search告诉我们:
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.
关于php array_search 具有多个命中的单个数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15841655/