PHP搜索数组用于部分或完全匹配

时间:2017-01-18 21:34:40

标签: php arrays

我有一个函数,它将在PHP中迭代一个数组,并且全部搜索一个值。

function checkarrayvalues($term, $arr, $strict = false) {
foreach ($arr as $item) {
    if (($strict ? $item === $term : $item == $term) || (is_array($item) && checkarrayvalues($term, $item, $strict))) {
        return true;
    }
}

所以我已经让它完成/完全匹配。但我还需要测试部分匹配,这是我现在失去的地方。例如,如果有人搜索" Dall"和#34;达拉斯"在数组中存在,它也需要在那里返回一个正数。

我在如何做到这一点上缺少什么?

数组看起来像:

 [Beau Rivage Resort & Casino] => Array
            (
                [name] => Beau Rivage Resort & Casino
                [nid] => 100
                [alias] => /BeauRivage
                [guestrooms] => 1740
                [meetingrooms] => 16
                [largestmr] => 17000
                [totalms] => 50000
                [picture] => /2016-12/Beau-Rivage-Fallen-Oak-Golf-Course_0.jpg
                [region] => SE
                [segment] => GC
                [city] => Biloxi
                [state] => MS
                [longstate] => mississippi
                [address] => 875 Beach Boulevard
                [zip] => 39530
                [country] => United States of America
                [distance] => 21.00
            )

        [Bellagio] => Array
            (
                [name] => Bellagio
                [nid] => 103
                [alias] => /Bellagio
                [guestrooms] => 3933
                [meetingrooms] => 50
                [largestmr] => 45000
                [totalms] => 200000
                [picture] => /2016-12/Bellagio-exterior.jpg
                [region] => SW
                [segment] => BB
                [city] => Las Vegas
                [state] => NV
                [longstate] => nevada
                [address] => 3600 Las Vega Boulevard South
                [zip] => 89109
                [country] => United States of America
                [distance] => 10.00
            ) 

1 个答案:

答案 0 :(得分:0)

"io.rancher.project_service.name" : "atlas-mosquitto/mosquitto"strposstripos函数使用以下扩展解决方案:

call_user_func