我有這樣的事情: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”,我需要將字符串值更改為另一個。你能幫助我嗎?問候我現(xiàn)在會更好地解釋:如果 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; }發(fā)生的情況是所有 Column1 列都錯誤地采用 NUMAX 值并且 column2 變?yōu)榭?
1 回答

aluckdog
TA貢獻1847條經(jīng)驗 獲得超7個贊
在 PHP 中比較是由===
not完成的=
,一個等號用于設(shè)置一個值。因此,更改=
為===
應(yīng)該可以解決問題。還有==
and ===
,兩個等號類型 juggles 和 triple 按原樣比較變量。2 == '2'
是真的,2 === '2'
是假的。
foreach ($all as $key => $row) { if ($row->Column1 === 'NUMAX') {
- 1 回答
- 0 關(guān)注
- 139 瀏覽
添加回答
舉報
0/150
提交
取消