我有这样的事情:Collection {#296 ▼#items: array:1318 [▼0 => {#289 ▼ +"Column1": "string1" +"Column2": "string2" +"Column3": "string3" +"Column4": "string4" +"Column5": "string5" }1 => {#292 ▼ +"Column1": "string6" +"Column2": "string7" +"Column3": "string8" +"Column4": "string9" +"Column5": "string10" }2 => {#293 ▼ +"Column1": "string11" +"Column2": "string12" +"Column3": "string13" +"Column4": "string14" +"Column5": "string15" }]} 对于每个“Column1”,我需要将字符串值更改为另一个。你能帮助我吗?问候我现在会更好地解释:如果 Column1 等于某个值,则 Column2 等于我的字符串我试过这个: foreach($all as $key=>$row){ if($row->Column1 = 'NUMAX'){ $ipoltstatus = Str::before($row->message, '_'); $olthostname = Olt::where('ipaddress', $ipoltstatus)->value('hostname'); $row->Column2 = $olthostname; }发生的情况是所有 Column1 列都错误地采用 NUMAX 值并且 column2 变为空
1 回答

aluckdog
TA贡献1847条经验 获得超7个赞
在 PHP 中比较是由===
not完成的=
,一个等号用于设置一个值。因此,更改=
为===
应该可以解决问题。还有==
and ===
,两个等号类型 juggles 和 triple 按原样比较变量。2 == '2'
是真的,2 === '2'
是假的。
foreach ($all as $key => $row) { if ($row->Column1 === 'NUMAX') {
- 1 回答
- 0 关注
- 121 浏览
添加回答
举报
0/150
提交
取消