猿问

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

我有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')


慕沐林林
浏览 166回答 3
3回答

郎朗坤

几个简单的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)
随时随地看视频慕课网APP
我要回答