我有2个数组,我试图找到任何匹配项并从$ array_full返回'url。我尝试了array_intersect($ array_full,$ array_ids),但是它不起作用。$array_full = array( Array ( '@attributes' => Array ( 'topicid' => 102000, 'url' => 'Velkommen.htm', 'alias' => 'Velkommen' ) ), Array ( '@attributes' => Array ( 'topicid' => 130313, 'url' => 'WStation/WAS_Indstillinger.htm', 'alias' => 'WAS_Indstillinger' ) ), Array ( '@attributes' => Array ( 'topicid' => 130315, 'url' => 'SPedestal/Applikationer/LoadSharing/Indstillinger.htm', 'alias' => 'LOS_Indstillinger' ) ), Array ( '@attributes' => Array ( 'topicid' => 130312, 'url' => 'WStation/WAS_Indstillinger.htm', 'alias' => 'WAS_Indstillinger' ) ));$array_ids = array('130312', '130315');我希望得到一个匹配的URL数组,例如:array('WStation/WAS_Indstillinger.htm','SPedestal/Applikationer/LoadSharing/Indstillinger.htm')
3 回答
![?](http://img1.sycdn.imooc.com/533e4c3300019caf02000200-100-100.jpg)
郎朗坤
TA贡献1921条经验 获得超9个赞
几个简单的foreach循环似乎是最简单的方法
$results = [];
foreach ( $array_full as $a ) {
foreach ( $a as $item ) {
if ( in_array($item['topicid'], $array_ids) ) {
$results[] = $item['url'];
}
}
}
print_r($results);
结果
Array
(
[0] => SPedestal/Applikationer/LoadSharing/Indstillinger.htm
[1] => WStation/WAS_Indstillinger.htm
)
- 3 回答
- 0 关注
- 162 浏览
添加回答
举报
0/150
提交
取消