functions

How to use array_diff (ar1, ar2 …) function in php

Example of array_diff() function
Example of array_diff() function

The array_diff() function compares ar1 against one or more other arrays and returns the values in ar2 that are not present in any of the other arrays.

Example

<?php
$array1 = array("lang" => "php", "java", ".net", "python");
$array2 = array("lang" => "perl", "java", "python");
$result = array_diff($array1, $array2);
print_r($result);
?>

Output of array_diff() function example
Output of example

About the author

Dinesh Sharma

I have worked on many CMS & Frameworks of PHP & I love to share my knowledge of what I am learning every day.

Add Comment

Click here to post a comment