Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove an array value from another array using PHP question

Tags:

php

I want to check if any of the array values from example 1 are in example 2 and remove them from example 2 if they are. How would I be able to do this using PHP?

Example 1

Array
(
    [0] => 3
    [1] => 5
)

Example 2

Array
(
    [0] => 3
    [1] => 3
    [2] => 4
    [3] => 4
    [4] => 4
    [5] => 3
    [6] => 3
    [7] => 3
    [8] => 4
    [9] => 4
    [10] => 4
    [11] => 3
)
like image 743
HELP Avatar asked Dec 05 '22 01:12

HELP


1 Answers

$example2 = array_diff($example2, $example1)

like image 146
Core Xii Avatar answered May 20 '23 14:05

Core Xii