php和从2个数组中删除变量

时间:2015-07-02 00:56:15

标签: php arrays

Array1
(
    [0] => 14
    [1] => 9
    [2] => 10
    [3] => 11
)


Array2
(
    [0] => 8
    [1] => 9
    [2] => 10
    [3] => 11
    [4] => 12
    [5] => 13
    [6] => 14
    [7] => 15
    [8] => 16
    [9] => 17
    [10] => 18
    [11] => 19
    [12] => 20
    [13] => 21
    [14] => 22
    [15] => 23
    [16] => 24

一些函数删除数组2上的array1值并创建一个array3 whit结果?

谢谢!

1 个答案:

答案 0 :(得分:1)

array_diff函数是您正在寻找的。感谢Paulpro找到这个函数的来源:https://stackoverflow.com/a/7241152/4912760。 您案例的代码示例:

$array3 = array_diff($array2, $array1);