Definition and usage of php array_diff function

巴扎黑
Release: 2023-03-07 21:06:01
Original
1851 people have browsed it

array_diff() Function meaning:

array_diff() function returns the difference array of two arrays. This array contains all keys that are in the array being compared, but are not in any of the other parameter arrays. In the returned array, the key names remain unchanged.

For example:

  "red","b"=>"green","c"=>"blue","d"=>"yellow"); $a2=array("e"=>"red","f"=>"green","g"=>"blue"); $result=array_diff($a1,$a2); print_r($result); ?> 
Copy after login

Run result:

Array ( [d] => yellow )
Copy after login

Syntax:

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

Parameter explanation:

array1 Required. The first array to compare with other arrays.

array2 Required. The array to compare to the first array.

array3,... Optional. Additional array to compare with the first array.

Tips and Notes

Tips: One or more arrays can be compared with the first array.

Note: Only values are used for comparison.

Return value: Returns the difference array, which includes all key values that are in the compared array (array1) but are not in any other parameter array (array2 or array3, etc.).

  "red","b"=>"green","c"=>"blue","d"=>"yellow"); $a2=array("e"=>"red","f"=>"black","g"=>"purple"); $a3=array("a"=>"red","b"=>"black","h"=>"yellow"); $result=array_diff($a1,$a2,$a3); print_r($result); ?> 
Copy after login

Run result:

Array ( [b] => green [c] => blue )
Copy after login

The above is the detailed content of Definition and usage of php array_diff function. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!