array_intersect多维数组内部 [英] array_intersect Inside multidimensional-array

查看:90
本文介绍了array_intersect多维数组内部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多维数组,可以根据用户输入增加.我想在数组内部做array_intersect以获得键之间的公共值.

i have an multidimensioanl array which can increase based on user input.i want to do array_intersect inside the array to get the common values between the key.

类似示例

Array ( [php] => Array ( [0] => 36 [1] => 51 [2] => 116 [3] => 171 [4] => 215 [5] => 219 [6] => 229 [7] => 247 [8] => 316 ) [java] => Array ( [0] => 14 [1] => 16 [2] => 19 [3] => 24 [4] => 25 [5] => 26 [6] => 29 [7] => 31 [8] => 33 [9] => 34 [10] => 35 [11] => 36 [12] => 37 [13] => 40 [14] => 45 [15] => 49 [16] => 51 ) ) 

预期输出应为(36,51)

expected output should be like (36,51)

这是我能够得到的

通过

$intersected_array = call_user_func_array('array_intersect', $array);

但是如果我的数组也有第三个键,那么这三个键都不具有相同的值

but if my array had a third key also which doesnot had a common value in all three of them

喜欢

Array ( [php] => Array ( [0] => 36 [1] => 51 [2] => 116 [3] => 171 [4] => 215 [5] => 219 [6] => 229 [7] => 247 [8] => 316 ) [java] => Array ( [0] => 14 [1] => 16 [2] => 19 [3] => 24 [4] => 25 [5] => 26 [6] => 29 [7] => 31 [8] => 33 [9] => 34 [10] => 35 [11] => 36 [12] => 37 [13] => 40 [14] => 45 [15] => 49 [16] => 51 ) [ajax] => Array ( [0] => 91 [1] => 110 [2] => 113 [3] => 172 ) ) 

然后,由于具有最大值的键的结果,它使我无法输出.在这种情况下,它将返回我所有java键的值.

then it is throwing me output as the result of the key having max values. in this case it will return me all the values of java key.

,但我的预期输出是0.请帮忙.

but my expected output is 0. please help.

推荐答案

我复制了您的示例,对我来说它可行:

I copyed you example and for me it works:

<?php

$array = array(
    'php' => array(
        36,
        51,
        116,
        171,
        215,
        219,
        229,
        247,
        316,
    ),
    'java' => array(
        14,
        16,
        19,
        24,
        25,
        26,
        29,
        31,
        33,
        34,
        35,
        36,
        37,
        40,
        45,
        49,
        51,
    ),
    'ajax' => array(
        91,
        110,
        113,
        172,
    ),
);

$intersected_array = call_user_func_array('array_intersect',$array);

print_r($intersected_array);

// RESULT: "Array ( ) "

请准确复制此代码,并告诉我您的输出.

Please copy exactly this code and tell me your output.

这篇关于array_intersect多维数组内部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆