I have a multidimensional array
Simple example array
[0]=>array(2) {
["slug"]=>string(12) "exampleslug1"
["tax"]=>string(11) "exampletax1"}
[1]=>array(2) {
["slug"]=>string(12) "exampleslug2"
["tax"]=>string(11) "exampletax2"}
[2]=>array(2) {
["slug"]=>string(12) "exampleslug2"
["tax"]=>string(11) "exampletax3"}
Now i want to check another multidimensional array for both values.
So for example. I want to check if the slug is "exampleslug2" and the tax = "exampletax2" So in this case it should return false/true/false.
Ive tried in_array but i can't seem to get that to work for multidimensional. Can anyone help me out with a solution for checking multiple values in the multidimensional array to be the same as in a second multidimensional array.
If it try something like
if (!in_array($termSlug, $externalTermSlugs['slug']) && !in_array($termTax, $externalTermSlugs['tax']) ) {}
It adds everything multiple times, what i want to have is that it adds everything once unique and doesn't overwrite if it already exists.
try this code
<?php
$arr = array( 0 => array("slug"=>"exampleslug1","tax"=>"exampletax1"),
1 => array("slug"=>"exampleslug2","tax"=>"exampletax2"),
2 => array("slug"=>"exampleslug2","tax"=>"exampletax3"));
foreach($arr as $key => $value){
if($value['slug']=="exampleslug2" && $value['tax']=="exampletax2"){
echo "true"."<br>";
}else{
echo "false"."<br>";
}
}
?>