a:array(4) { [api/index/index] => string(3) 226 [main/index/index] => string(3) 227 [main/index/main] => string(3) 228 [/main/index/test] => string(3) 229}b:array(22) { [/main/index/test] => int(3) [/main/index/liebiao/text/%e5%88%97%e8%a1%a8%e6%b5%8b%e8%af%95] => string(7) 0-sec-0 [/main/index/test/text/%e7%a8%8e%e6%94%b6%e5%88%86%e6%9e%902] => string(7) 0-sec-1 [/main/index/test/text/%e7%a8%8e%e6%94%b6%e5%88%86%e6%9e%903] => string(7) 0-sec-2 [/main/index/test/text/%e7%a8%8e%e6%94%b6%e6%95%b0%e6%8d%ae1] => string(7) 1-sec-0 [/main/index/test/text/%e7%a8%8e%e6%94%b6%e6%95%b0%e6%8d%ae2] => string(7) 1-sec-1 [/main/index/test/text/%e7%a8%8e%e6%94%b6%e6%95%b0%e6%8d%ae3] => string(7) 1-sec-2 [/main/index/test/text/%e4%bc%81%e4%b8%9a%e7%ae%a1%e7%90%861] => string(7) 2-sec-0 [/main/index/test/text/%e4%bc%81%e4%b8%9a%e7%ae%a1%e7%90%862] => string(7) 2-sec-1 [/main/index/test/text/%e4%bc%81%e4%b8%9a%e7%ae%a1%e7%90%863] => string(7) 2-sec-2 [/main/index/test/text/%e7%b3%bb%e7%bb%9f%e8%ae%be%e7%bd%ae1] => string(7) 3-sec-0 [/main/tree/index/text/%e6%a0%91%e7%8a%b6%e7%ae%a1%e7%90%86] => string(7) 3-sec-1 [/main/test/index/text/%e5%88%97%e8%a1%a8%e6%b5%8b%e8%af%95] => string(7) 3-sec-2 [/ucenter/user/index/text/%e7%94%a8%e6%88%b7%e7%ae%a1%e7%90%86] => string(7) 3-sec-3 [/system/config/index/text/%e9%85%8d%e7%bd%ae%e7%ae%a1%e7%90%86] => string(7) 3-sec-4 [/system/index/index] => int(4) [/system/subject/index/text/%e5%9f%ba%e7%a1%80%e8%ae%be%e7%bd%ae] => string(7) 4-sec-0 [/system/industry/index/text/%e5%9f%ba%e7%a1%80%e8%ae%be%e7%bd%ae] => string(7) 4-sec-1 [/system/area/index/text/%e5%9f%ba%e7%a1%80%e8%ae%be%e7%bd%ae] => string(7) 4-sec-2 [/system/flatrate/index/text/%e5%9f%ba%e7%a1%80%e8%ae%be%e7%bd%ae] => string(7) 4-sec-3 [/system/settlement/index/text/%e5%9f%ba%e7%a1%80%e8%ae%be%e7%bd%ae] => string(7) 4-sec-4 [/system/split/index/text/%e5%9f%ba%e7%a1%80%e8%ae%be%e7%bd%ae] => string(7) 4-sec-5}
有以上两个数组,现需要知道其中重复的有哪些
如何算是重复
第一种情况 比如a数组权限中的key为/main/index/test b数组菜单的key为/main/index/test 可算是重复的
第二种情况 比如a数组权限中的key为main/index/test b数组菜单的key为/main/index/test/text/fdsfsdfljl 也算作是重复数据
以上两种情况均算作将b数组的改key放入到c数组中作为交集使用
请问如何使用较少的时间来求这两个数组的交集。
我能想到的是foreach 进行循环 单条单条的匹配,但是当a中的规则有几千上百的时候,b中的菜单项也几十上百时,就会有较明显的卡顿现象,不知道谁有更好的方法能够减少循环次数节省运行时间的方法
回复内容: a:array(4) { [api/index/index] => string(3) 226 [main/index/index] => string(3) 227 [main/index/main] => string(3) 228 [/main/index/test] => string(3) 229}b:array(22) { [/main/index/test] => int(3) [/main/index/liebiao/text/%e5%88%97%e8%a1%a8%e6%b5%8b%e8%af%95] => string(7) 0-sec-0 [/main/index/test/text/%e7%a8%8e%e6%94%b6%e5%88%86%e6%9e%902] => string(7) 0-sec-1 [/main/index/test/text/%e7%a8%8e%e6%94%b6%e5%88%86%e6%9e%903] => string(7) 0-sec-2 [/main/index/test/text/%e7%a8%8e%e6%94%b6%e6%95%b0%e6%8d%ae1] => string(7) 1-sec-0 [/main/index/test/text/%e7%a8%8e%e6%94%b6%e6%95%b0%e6%8d%ae2] => string(7) 1-sec-1 [/main/index/test/text/%e7%a8%8e%e6%94%b6%e6%95%b0%e6%8d%ae3] => string(7) 1-sec-2 [/main/index/test/text/%e4%bc%81%e4%b8%9a%e7%ae%a1%e7%90%861] => string(7) 2-sec-0 [/main/index/test/text/%e4%bc%81%e4%b8%9a%e7%ae%a1%e7%90%862] => string(7) 2-sec-1 [/main/index/test/text/%e4%bc%81%e4%b8%9a%e7%ae%a1%e7%90%863] => string(7) 2-sec-2 [/main/index/test/text/%e7%b3%bb%e7%bb%9f%e8%ae%be%e7%bd%ae1] => string(7) 3-sec-0 [/main/tree/index/text/%e6%a0%91%e7%8a%b6%e7%ae%a1%e7%90%86] => string(7) 3-sec-1 [/main/test/index/text/%e5%88%97%e8%a1%a8%e6%b5%8b%e8%af%95] => string(7) 3-sec-2 [/ucenter/user/index/text/%e7%94%a8%e6%88%b7%e7%ae%a1%e7%90%86] => string(7) 3-sec-3 [/system/config/index/text/%e9%85%8d%e7%bd%ae%e7%ae%a1%e7%90%86] => string(7) 3-sec-4 [/system/index/index] => int(4) [/system/subject/index/text/%e5%9f%ba%e7%a1%80%e8%ae%be%e7%bd%ae] => string(7) 4-sec-0 [/system/industry/index/text/%e5%9f%ba%e7%a1%80%e8%ae%be%e7%bd%ae] => string(7) 4-sec-1 [/system/area/index/text/%e5%9f%ba%e7%a1%80%e8%ae%be%e7%bd%ae] => string(7) 4-sec-2 [/system/flatrate/index/text/%e5%9f%ba%e7%a1%80%e8%ae%be%e7%bd%ae] => string(7) 4-sec-3 [/system/settlement/index/text/%e5%9f%ba%e7%a1%80%e8%ae%be%e7%bd%ae] => string(7) 4-sec-4 [/system/split/index/text/%e5%9f%ba%e7%a1%80%e8%ae%be%e7%bd%ae] => string(7) 4-sec-5}
有以上两个数组,现需要知道其中重复的有哪些
如何算是重复
第一种情况 比如a数组权限中的key为/main/index/test b数组菜单的key为/main/index/test 可算是重复的
第二种情况 比如a数组权限中的key为main/index/test b数组菜单的key为/main/index/test/text/fdsfsdfljl 也算作是重复数据
以上两种情况均算作将b数组的改key放入到c数组中作为交集使用
请问如何使用较少的时间来求这两个数组的交集。
我能想到的是foreach 进行循环 单条单条的匹配,但是当a中的规则有几千上百的时候,b中的菜单项也几十上百时,就会有较明显的卡顿现象,不知道谁有更好的方法能够减少循环次数节省运行时间的方法
有官方函数可以直接干这个事情啊... 随手写大概是这个样子的:
array_intersect_uassoc($a, $b, function($ka, $kb) { if( preg_match(%$ka%i, $kb) ) return 0; return $ka - $kb;});