Set Theory Union of arrays in PHP

后端 未结 10 844
独厮守ぢ
独厮守ぢ 2020-12-14 06:14

There are 3 operations with sets in mathematics: intersection, difference and union (unification). In PHP we can do this operations with arrays:

  • intersection:
10条回答
  •  时光取名叫无心
    2020-12-14 06:57

    The + operator:

    $x[0] = 4;
    $x[1] = 1;
    
    $y[0] = 9;
    $y[2] = 5;
    
    $u = $y + $x;
    
    // Results in:
    $u[0] === 9;
    $u[1] === 1;
    $u[2] === 5;
    

    Note that $x + $y != $y + $x

提交回复
热议问题