为了账号安全,请及时绑定邮箱和手机立即绑定

如何从匹配的两个数组中获取键值?

如何从匹配的两个数组中获取键值?

PHP
慕沐林林 2021-05-04 15:25:39
我有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 回答

?
郎朗坤

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

)


查看完整回答
反对 回复 2021-05-14
  • 3 回答
  • 0 关注
  • 162 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信