I have an array
$check = ['a', 'b', 'c'];
which I want to check against another array so that the values of $check
should match the keys in $actual
$actual = ['a' => 'one', 'b' => 'two', 'c' => 'three'];
I can't use array_diff() === []
since array diff works on comparing the values and in this case I want to compare the values of one array against the keys in another.
You can use array_keys();
<?php
$check = ['a', 'b', 'c'];
$actual = ['a' => 'one', 'b' => 'two', 'c' => 'three'];
$result = array_diff(array_keys($actual), $check);
print_r($result);
In this case array_diff returns a empty array because all keys are found