我之前有一个<html>day</html>
,之后有一个。{/ p>
为什么(以及何时)var_dump
被修改为foreach只是复制变量中的值?
我有这段代码:
$data->offers
首先<?php
data = new stdClass();
$data->offers = $this->getOffreChildren(27);
var_dump($data->offers);
foreach ($data->offers as $offre) {
$offre->contracts = $this->getOffreChildren($offre->id);
foreach ($offre->contracts as $contract) {
$contract->count = 0;
foreach ($adhesions as $adhesion) {
if ($adhesion->id_type_contrat == $contract->id)
$contract->count = $adhesion->nombre;
}
}
}
var_dump($data->offers); die;
:
var dump
第二个array (size=7)
0 =>
object(stdClass)[260]
public 'nom' => string 'lorem' (length=6)
public 'id' => string '1' (length=1)
public 'code' => string 'lorem' (length=5)
1 =>
object(stdClass)[261]
public 'nom' => string 'lorem.... ' (length=19)
public 'id' => string '2' (length=1)
public 'code' => string 'lorem..... lorem' (length=13)
2 =>
object(stdClass)[262]
public 'nom' => string 'lorem...lorem' (length=17)
public 'id' => string '48' (length=2)
public 'code' => string 'lorem...lorem' (length=16)
....
:
var_dump
答案 0 :(得分:1)
Foreach
遍历您的数组,并在您的情况下使用命令
contracts
属性
$offre->contracts = $this->getOffreChildren($offre->id);
目前尚不清楚$adhesions
来自哪里,但
$contract->count = $adhesion->nombre;
您将另一个属性添加到已添加的contracts
属性。