Home >> PHP >> What is the difference between array_intersect_assoc() and array_intersect_key() in PHP

What is the difference between array_intersect_assoc() and array_intersect_key() in PHP

The array_intersect_assoc() function used for compares the keys and values of two or more arrays, and returns the common elements.

Example

$array1 = array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$array2 = array("a"=>"red","b"=>"green","c"=>"red");

print_r(array_intersect_assoc($array1,$array2));

Output

Array ( [a] => red [b] => green)

The array_intersect_key() function used for compares the keys of two or more arrays, and returns common elements.

Example

$array1 = array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$array2 = array("a"=>"red","b"=>"green","c"=>"red");

print_r(array_intersect_key($array1,$array2));

Output

Array ( [a] => red [b] => green [c] => blue )

Post Your Comment

Next Questions
What is difference between array_push() and array_pop()
What is difference between array_product() and array_sum()
What is the difference between session and cookie
What is session & work
What are data types
What are super global variable
$GLOBALS super global variable
$_SERVER super global variable
$_REQUEST super global variable
$_POST super global variable
$_GET super global variable
$_FILES super global variable
$_ENV super global variable
$_COOKIE super global variable
$_SESSION super global variable
Ternary operator
Variable types
What is password encrypt and decrypt function
Difference between echo and print
How can destroy and unset the variable of a session
Function
isset() function
unset() function
empty() function
What are function for controlling script execution

Copyright ©2022 coderraj.com. All Rights Reserved.