I'm working with Laravel 8 and I need to concatenate an object with an arrow operator and then a custom variable like this:
$fullStr = "product_attr_correction";
dd($product->$fullStr); // return null incorrectly
So basically, at the table products
I have a column name product_attr_correction
and it already has a value in it.
But the result of dd($product->$fullStr)
return null incorrectly.
But when I do dd($product->product_attr_correction)
, I get the proper result value.
So the question is, how can I combine an object with an arrow operator and then a custom variable properly?
使用此语法:
$product->{$fullStr}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.