$a = array("a","b");
$b = array("a"=>"one", "b" => "two","c"=>"three");
I need help in finding the difference between two arrays one with key and another without key.
required output
"c"=>"three"
Use array_diff_key()
and array_flip()
:
$difference = array_diff_key(
$b,
array_flip($a)
);
For reference, see:
For an example, see:
Every array has keys. Even if you have not set them.
So, your arrays look like this:
$a = array(0=>"a",1=>"b");
$b = array("a"=>"one", "b" => "two","c"=>"three");
And you trying to compare the values of one array with the keys of the other.
That's why localheinz is using array_flip()
in his answer.