Maison > développement back-end > tutoriel php > 回到两个数组的交集

回到两个数组的交集

WBOY
Libérer: 2016-06-13 10:53:09
original
824 Les gens l'ont consulté

返回两个数组的交集
A数组

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->array(    [0] =>        array(        ['action_id'] =>        3        )    [1] =>        array(        ['action_id'] =>        2    )    [2] =>        array(        ['action_id'] =>        1    )    [3] =>        array(        ['action_id'] =>        7    )    [4] =>        array(        ['action_id'] =>        11    ))
Copier après la connexion

B数组:
PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->array(    [0] =>    array(    ['action_id'] =>    3        ['type'] =>        0        ['order_num'] =>        67    )    [1] =>    array(    ['action_id'] =>    2        ['type'] =>        0        ['order_num'] =>        66    )    [2] =>    array(    ['action_id'] =>    1        ['type'] =>        0        ['order_num'] =>        65    )    [3] =>    array(    ['action_id'] =>    7        ['type'] =>        0        ['order_num'] =>        64        )    [8] =>    array(    ['action_id'] =>    14        ['type'] =>        0        ['order_num'] =>        40        )    [13] =>    array(    ['action_id'] =>    11        ['type'] =>        0        ['order_num'] =>        30    ))
Copier après la connexion

使用array_intersect_key返回的为什么是
PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->array(    [0] =>    array(    ['action_id'] =>    3        ['type'] =>        0        ['order_num'] =>        67    )    [1] =>    array(    ['action_id'] =>    2        ['type'] =>        0        ['order_num'] =>        66    )    [2] =>    array(    ['action_id'] =>    1        ['type'] =>        0        ['order_num'] =>        65    )    [3] =>    array(    ['action_id'] =>    7        ['type'] =>        0        ['order_num'] =>        64        )    )
Copier après la connexion

action_id为11的为什么没了??

------解决方案--------------------
PHP code
$a = array(  0 => array('action_id' => 3),  1 => array('action_id' => 2),  2 => array('action_id' => 1),  3 => array('action_id' => 7),  4 => array('action_id' => 11),);$b = array(  0 => array('action_id' => 3, 'type' => 0, 'order_num' => 67),  1 => array('action_id' => 2, 'type' => 0, 'order_num' => 66),  2 => array('action_id' => 1, 'type' => 0, 'order_num' => 65),  3 => array('action_id' => 7, 'type' => 0, 'order_num' => 64),  8 => array('action_id' => 14, 'type' => 0, 'order_num' => 40),  13 => array('action_id' => 11, 'type' => 0, 'order_num' => 30),);foreach($a as $v) $dict[] = $v['action_id'];foreach($b as $k=>$v) if(in_array($v['action_id'], $dict)) $c[$k] = $v;print_r($c);<div class="clear">
                 
              
              
        
            </div>
Copier après la connexion
Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal