两个数组foreach回声

时间:2019-10-12 12:30:14

标签: php arrays for-loop foreach

我无法显示我的数据。我有2个数组,我想检查数组2是否等于数组1。在输出下面的示例数组中,应该像这样。任何答案将不胜感激。我是新手

  

100000,010000,010000,000001,000001,100000,100000

数组1数据

array(6) {
  [0]=>
  object(stdClass)#370 (1) {
    ["id"]=>
    string(1) "1"
  }
  [1]=>
  object(stdClass)#369 (1) {
    ["id"]=>
    string(1) "2"
  }
  [2]=>
  object(stdClass)#368 (1) {
    ["id"]=>
    string(1) "3"
  }
  [3]=>
  object(stdClass)#367 (1) {
    ["id"]=>
    string(1) "4"
  }
  [4]=>
  object(stdClass)#366 (1) {
    ["id"]=>
    string(1) "5"
  }
  [5]=>
  object(stdClass)#365 (1) {
    ["id"]=>
    string(1) "6"
  }
}

数组2数据

array(7) {
  [0]=>
  object(stdClass)#354 (1) {
    ["stage_id"]=>
    string(1) "1"
  }
  [1]=>
  object(stdClass)#355 (1) {
    ["stage_id"]=>
    string(1) "2"
  }
  [2]=>
  object(stdClass)#353 (1) {
    ["stage_id"]=>
    string(1) "2"
  }
  [3]=>
  object(stdClass)#352 (1) {
    ["stage_id"]=>
    string(1) "6"
  }
  [4]=>
  object(stdClass)#378 (1) {
    ["stage_id"]=>
    string(1) "6"
  }
  [5]=>
  object(stdClass)#377 (1) {
    ["stage_id"]=>
    string(1) "1"
  }
  [6]=>
  object(stdClass)#376 (1) {
    ["stage_id"]=>
    string(1) "1"
  }
}

这是我尝试过的并且不起作用。它只显示100000

foreach ($this->stage as $index => $object)
{
    if (isset($this->items[$index]) && $object->id == $this->items[$index]->stage_id)
    {
        echo 1;
    }
    else
    {
        echo 0;
    }
}

0 个答案:

没有答案