Jump to content
Truman

array_diff_key()

Recommended Posts

I don't understand this array function although I read php manual.

This is an example:


<?php
$array1 = array('blue'  => 1, 'red'  => 2, 'green'  => 3, 'purple' => 4);
$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan'   => 8);

var_dump(array_diff_key($array1, $array2));
?>

and this is output:

array(2) {  ["red"]=>  int(2)  ["purple"]=>  int(4)}

I don't see any connection here, why is for example key red different from the key blue in the second array but the key blue from the first arrays differs from the key green in the second array? Or I got this completely wrong?

Share this post


Link to post
Share on other sites

array1 keys not in array2 difference

 

blue in 1 and 2. = yes

red in 1 and 2 = no, only array1

green in 1 and 2 = yes

purple in 1 and 2 = no, only array1

 

difference is of all keys values in array1, keys 'red' and 'purple' are not found in array2.

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×