0

I have something like this:

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"
 }
]
}     

For each "Column1" I need to change the string value to another. Can you help me? Regards

I'll explain better now:

if Column1 is equal to a certain value, then Column2 is equal to my string

I have tried this:

 foreach($all as $key=>$row){
        if($row->Column1 = 'NUMAX'){
            $ipoltstatus = Str::before($row->message, '_');
            $olthostname = Olt::where('ipaddress', $ipoltstatus)->value('hostname');

            $row->Column2 = $olthostname;

        }

what happens is that all Column1 columns mistakenly take the NUMAX value and column2 becomes empty

DMU
  • 69
  • 8

1 Answers1

0

In PHP comparison is done by === not =, a single equal sign is for setting a value. So changing = to === should do the trick. Also there is == and ===, two equal signs type juggles and triple compares the variables as is. 2 == '2' is true and 2 === '2' is false.

foreach ($all as $key => $row) {
    if ($row->Column1 === 'NUMAX') {
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
mrhn
  • 17,961
  • 4
  • 27
  • 46