I have two arrays and these arrays contain information about id, linklabel and url in the following format:
$pageids = [
['id' => 1, 'linklabel' => 'Home', 'url' => 'home'],
['id' => 2, 'linklabel' => 'Graphic Design', 'url' => 'graphicdesign'],
['id' => 3, 'linklabel' => 'Other Design', 'url' => 'otherdesign'],
['id' => 6, 'linklabel' => 'Logo Design', 'url' => 'logodesign'],
['id' => 15, 'linklabel' => 'Content Writing', 'url' => 'contentwriting'],
];
$parentpage = [
['id' => 2, 'linklabel' => 'Graphic Design', 'url' => 'graphicdesign'],
['id' => 3, 'linklabel' => 'Other Design', 'url' => 'otherdesign'],
];
I'm now trying to compare these two in order to find the information that is in $pageids but NOT in $parentpage - this will then make up another array called $pageWithNoChildren. However when I use the following code:
$pageWithNoChildren = array_diff_assoc($pageids,$parentpage);
The array_diff_assoc() runs on the first level of the arrays and therefore sees that both $pageids and $parentpages have a [0] and [1] key so it ignores them and returns all the information from $pageids from [2] onwards. However I want it to look at the content of the nested arrays and compare those e.g. I need it to see which id, linklabel and url are in $pageids and not in $parentpages and return those values.
How can I get the array_diff_assoc() to run on the keys of the nested arrays and not the keys of the first arrays so the final result is an array that contains the contents of the [0], [3] and [4] arrays from $pageids?
Expected Result:
array (
0 =>
array (
'id' => 1,
'linklabel' => 'Home',
'url' => 'home',
),
3 =>
array (
'id' => 6,
'linklabel' => 'Logo Design',
'url' => 'logodesign',
),
4 =>
array (
'id' => 15,
'linklabel' => 'Content Writing',
'url' => 'contentwriting',
),
)