R Robert9 Well-known member Nov 22, 2023 #1 How can I do: Code: $item->color = $item->size = $item->weight = as Code: $fieldList = "color,size,weight"; $fieldArray = explode(",",$fieldList); foreach ($fieldArray as $k => $v) { $item->$v = something; } Last edited: Nov 22, 2023
How can I do: Code: $item->color = $item->size = $item->weight = as Code: $fieldList = "color,size,weight"; $fieldArray = explode(",",$fieldList); foreach ($fieldArray as $k => $v) { $item->$v = something; }
R Robert9 Well-known member Nov 22, 2023 #2 Seems to work with $item->{$v} = something; and there should be no spaces inside the list "color,size,weight";
Seems to work with $item->{$v} = something; and there should be no spaces inside the list "color,size,weight";