How to use array diff in PHP
In this article, I will explain how the array_diff() function can be used in PHP.
array_diff() function in PHP
-
The array_diff() function compares two or more arrays, and returns an array with the keys and values from the first array.
-
The array_diff() function is used to find the difference of given arrays.
Syntax
array_diff(array1,array2,array3....) |
Parameter
-
array1 array1 is required parameter. The first array is the array which will be compared with other arrays.
-
array2 array2 is required parameter. An array to be compared with the first array.
-
array3 array3 is optional parameter. An array to be compared with the first array.
Example
The following example show to how the array_diff() function can be used in PHP.
<h3 style="color:green;">array_diff() function example in PHP</h3>
<?php
$i1=array(0=>"Student",1=>"Doctor",2=>"Advocate");
$i2=array(3=>"Student",4=>"Doctor",5=>"Worker");
print_r(array_diff($i1,$i2));
?> |
Output
You may also want to read these related articles here
Ask Your Question
Got a programming related question? You may want to post your question here