- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
array_intersect_ukey() function in PHP
The array_intersect_ukey() function compares array keys, with an additional user-made function check, and returns the matches. The function returns an array containing the entries from the first array that are present in all of the other arrays.
Syntax
array_intersect_ukey(arr1, arr2, arr3, arr4, …, compare_func)
Parameters
arr1 − Array to compare from. Required.
arr2 − Array to compare against. Required.
arr3 − You can add more arrays to compare. Optional.
arr4 − You can add more arrays to compare. Optional.
compare_func − This callback function must return an integer <, =, or > than 0 if the first argument is considered to be respectively <, =, or > than the second.
Return
The array_intersect_ukey() function returns an array containing the entries from the first array that are present in all of the other arrays.
Example
The following is an example that compares the keys.
<?php function check($a,$b) { if ($a===$b) { return 0; } return ($a>$b)?1:-1; } $arr1 = array("a"=>"one","b"=>"two","c"=>"three"); $arr2 = array("a"=>"one","b"=>"two"); $result = array_intersect_ukey($arr1,$arr2,"check"); print_r($result); ?>
Output
Array ( [a] => one [b] => two )