doqp87012
2013-01-12 07:36
浏览 123
已采纳

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.

like example

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 ) ) 

expected output should be like (36,51)

and this is i am able to get it

via this,

$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

like

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 ) ) 

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.

but my expected output is 0. please help.

图片转代码服务由CSDN问答提供 功能建议

我有一个multidimensioanl数组,可以根据用户输入增加。我想在数组内部执行array_intersect以获取 密钥之间的公共值。

例如

  Array([php] => Array([0] => 36  [1] => 51 [2] => 116 [3] => 171 [4] => 215 [5] => 219 [6] => 229 [7] => 247 [  8] => 316)[java] =>数组([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)

这是我能够得到它

通过这个,

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

但是如果我的数组还有第三个键也是 它们在所有这三个中都没有共同的值

喜欢< / p>

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

然后 由于具有最大值的键,它将输出作为输出。 在这种情况下,它将返回 java 键的所有值。

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

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongmeiran609914 2013-01-12 07:52
    已采纳

    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.

    打赏 评论

相关推荐 更多相似问题