2018-07-05 09:48
浏览 78


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.

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dougao7801 2018-07-05 09:57

    try this code

    $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>";
            echo "false"."<br>";
    打赏 评论

相关推荐 更多相似问题