开发者

Can I invert diff_assoc_array() by performing it twice?

Would running array_diff_assoc() twice on an array give me a开发者_StackOverflow社区ll non-unique entries?

$array3 = array_diff_assoc($array1, $array2);
$array4 = array_diff_assoc($array1, $array3);
var_dump($array4);


Given:

  • A the set of entries in $array1, and
  • B the set of entries in $array2,

B would be composed of:

  • B', all the entries in B that are in A, and
  • B'' all the entries in B that are not in A.

$array3, diff_assoc_array($array1, $array2), would be the operation A \ B, which would reduces as follows:

  • (A \ B') ∩ (A \ B'')
  • (A ∩ ¬B') ∩ A
  • A ∩ ¬B'.

$array4, diff_assoc_array($array1, $array3), would be the operation A \ (A ∩ ¬B'), which reduces as follows:

  • A ∩ ¬(A ∩ ¬B')
  • A ∩ (¬A ∪ B')
  • A ∩ B

Therefore yes, the final result would be the items common to both arrays.


Solved...

<?php
  $array1 = array(0, 1, 2);
  $array2 = array("00", "01", 2);
  $array3 = array_diff_assoc($array1, $array2);
  $array4 = array_diff_assoc($array1, $array3);
  var_dump($array3);
  echo "<br><br>";
  var_dump($array4);
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜