比较阵列

时间:2016-12-22 05:40:44

标签: php arrays apriori

我有两个数组如下:

$cmobine = array (
    [0] => Array
        (
            [0] => KAWAT LOKET 1/2 HIJAU 10M
            [1] => KAWAT LOKET 1/4 HIJAU 10M
        )

    [1] => Array
        (
            [0] => KAWAT LOKET 1/2 HIJAU 10M
            [1] => KUAS ETERNA 4"
        )

    [2] => Array
        (
            [0] => KAWAT LOKET 1/2 HIJAU 10M
            [1] => SIKU LUBANG
        )

    [3] => Array
        (
            [0] => SIKU LUBANG
            [1] => KUAS ETERNA 4"
        )
)

还有第二个阵列:

$transaction = array (
  [003352] => Array
        (
            [0] => KAWAT LOKET 1/2 HIJAU 10M
            [1] => KAWAT LOKET 1/4 HIJAU 10M
        )

  [003353] => Array
        (
            [0] => BODI LIDAH PELOR SS 2036-402 SES
            [1] => KAWAT LOKET 1/2 HIJAU 10M
            [2] => SIKU LUBANG
        )

  [003363] => Array
        (
            [0] => ENGSEL TIPIS BRAS 2 + SKRUP
            [1] => ENGSEL TIPIS BRAS 2 1/2 + SKRUP
            [2] => KUAS ETERNA 4"
            [3] => LAMSKAR SN
            [4] => MASKER HIDUNG
            [5] => OBENG BB ANOVI
            [6] => PAKU BETON  30
            [7] => PAKU BETON HITAM 50
            [8] => SIKU LUBANG
            [9] => PAKU BETON PUTIH 5
            [10] => SARINGAN GOT STAINLIS NISHIO
        )

  [003366] => Array
        (
            [0] => GRENDEL BABET GP 2" GOMEO
            [1] => GRENDEL STANLIS IMPERIAL 2"
        )
);

然后根据比较数组生成这样的数组:

$result = array (

    [0] => Array
        (
            [0] => KAWAT LOKET 1/2 HIJAU 10M
            [1] => KAWAT LOKET 1/4 HIJAU 10M
        )

    [1] => Array
        (
            [0] => KAWAT LOKET 1/2 HIJAU 10M
            [1] => SIKU LUBANG
        )

    [2] => Array
        (
            [0] => SIKU LUBANG
            [1] => KUAS ETERNA 4"
        )
);
$ombine值进行比较的

$transaction值,如果匹配,则结果为$combine本身的值。 根据上面的$results

1 个答案:

答案 0 :(得分:0)

在这种情况下,使用array_diff_assoc()可能有所帮助。