문제

I have an array like

<?php
 $array1 = array(1,2,3,5);
 $array2 = array(1,3,4,5,6,7);

?> 

i want $array3 to look like

 $array3 = array(4,6,7);

In simple words remove elements of $array2 if contained in $array1 i am a newbie searched a lot but didnt found anything.Help would be thanked.

도움이 되었습니까?

해결책

Use array_diff():

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

Note that the order of arguments is important here. The above statement checks $array2 against $array1 and returns the values in $array2 that are not present in $array1.

Output:

Array
(
    [2] => 4
    [4] => 6
    [5] => 7
)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top