通过此php关联对象数组搜索和比较的最快方法

时间:2018-11-29 19:20:05

标签: search compare time-complexity associative-array

(array) Array
(
    [0] => WP_Term Object
        (
            [term_id] => 1474
            [name] => Bij
            [slug] => bij
            [term_group] => 0
            [term_taxonomy_id] => 1474
            [taxonomy] => brand_name
            [description] => 
            [parent] => 0
            [count] => 14
            [filter] => raw
            [term_order] => 0
        )

    [1] => WP_Term Object
        (
            [term_id] => 1109
            [name] => Cal
            [slug] => cal
            [term_group] => 0
            [term_taxonomy_id] => 1109
            [taxonomy] => brand_name
            [description] => 
            [parent] => 0
            [count] => 16
            [filter] => raw
            [term_order] => 0
        )

    [2] => WP_Term Object
        (
            [term_id] => 1166
            [name] =>Glue-
            [slug] => clear-glue
            [term_group] => 0
            [term_taxonomy_id] => 1166
            [taxonomy] => brand_name
            [description] => 
            [parent] => 0
            [count] => 3
            [filter] => raw
            [term_order] => 0
        )

我有一个搜索字词($ brand_query),我正在与上述数组($ brand_names)的子弹和类似名称进行比较

 for($i=0; $i<sizeof($brand_names); $i++){
            if($brand_query==$brand_names[$i]->name||$brand_query1==$brand_names[$i]->slug){//if search matches with the name or slug do something

            }

        } 

使用array_search或任何此类内置函数可以提高搜索和比较的速度吗?

0 个答案:

没有答案