PHP function of the day: array_diff()

For day 11 of 21 in the “PHP Function of the day” series, I’m going to look at array_diff(). It gets the difference between an array and one or more other arrays.

Let’s take a look.


$person1 = array(“fname”=>”Joe”,”lname”=>”Smith”);

$person2 = array(“fname”=>”Jane”,”lname”=>”Smith”);

$differences = array_diff($person1, $person2);


$person3 = array(“fname”=>”Stan”,”lname”=>”Smith”);

$differences = array_diff($person1, $person2, $person3);




See the output


In the above example, $person1 is being compared to $person2 and $person3.  That’s the reason why the result in both comparisons is “Joe”.

Leave a Reply

Your email address will not be published.