0

什么是我可以使用的功能,基本上与做相反

if(strpos($array['some_key'], $value)!==false) {
    that means there's a match and confinue
}

我基本上想遍历两个数组并获取与 in 不匹配的$value数组$array

    $array = 

      Array
            (
            [0] => GPPZ20
            [1] => GPPZ45
            [2] => GPPZ75
            [3] => GPPZH20
            [4] => GPPZH45
       )


     $codes = 

        Array
    (
     [0] => Array
      (
        [count] => 1
        [code] => GPPZH20SWYE4A2VZU
        [amount] => 20
    )

    )

      Array
     (
       [0] => Array
      (
        [count] => 1
        [code] => GPPZH2077434178J6
        [amount] => 20
    )

      )

    Array
(
   [0] => Array
    (
        [count] => 17
        [code] => PMMC4
        [amount] => 25
    )

)

Array
(
[0] => Array
    (
        [count] => 1
        [code] => GPPZH2052910M8V62
        [amount] => 20
    )

)

Array
(
[0] => Array
    (
        [count] => 1
        [code] => GPPZH45B3116LD1VW
        [amount] => 45
    )

 )

所以我想要做的是获取 $codes 数组中 $codes['code'] 值与 $array 值中的任何值都不匹配的所有值。

现在我有那些匹配并通过做抓住那些

  foreach($codes as $code) {
      foreach($array as $key=>$value) {
         if(strpos($code['code'], $value)!==false) {
              //it matches grab those values
         }
       }
  }  

我现在基本上需要这样的东西来抓住那些不匹配的东西

4

1 回答 1

0

您应该使用array_filter函数 - http://php.net/manual/en/function.array-filter.php例如:

function myFilter($val){ return strpos('foo', $val) === false; }
$array = array("foobar", "foo", "bar");
var_dump(array_filter($array, myFilter));

您也可以使用preg_matchmethod 代替strpos.

于 2013-01-04T21:55:32.733 回答