Bladephp: Now with 7+ codeigniter, php, and laravel project 7+ php project From $18/Year From Rs. 1000/Year

PHP array_diff() Function

by
Category:php
php php array function
PHP array_diff() Function

The array_diff() function compares the values of two (or more) arrays, and returns the differences.

You can diff several arrays by providing more parameters. The function will return an array of values in the first array that do not appear in the second and subsequent arrays.

Parameter Description
array1 Required. The specified array which will be compared with other arrays.
array2 Required. Compared with the first array.
array3,... Optional. Compared with the first array.

Syntax

array_diff(array1,array2,array3...);

Example

$array1=array("a"=>"Prince","b"=>"James","c"=>"Samuel","d"=>"Cooper");
$array2=array("e"=>"Prince","f"=>"James","g"=>"Samuel");
$result=array_diff($array1,$array2);
print_r($result);

Output

Array ( [d] => Cooper ) 

0 Comments


Html code work in comment box


Related Post