猿问

将数字组的字符值更改为另一个字符值

我有这样的事情:


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 变为空


哔哔one
浏览 122回答 1
微课
1回答

aluckdog

在 PHP 中比较是由===not完成的=,一个等号用于设置一个值。因此,更改=为===应该可以解决问题。还有==and ===,两个等号类型 juggles 和 triple 按原样比较变量。2 == '2'是真的,2 === '2'是假的。foreach ($all as $key => $row) {     if ($row->Column1 === 'NUMAX') {
随时随地看视频慕课网APP
我要回答