'How to combine an object with an arrow operator and then a custom variable
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?
Solution 1:[1]
Use this syntax :
$product->{$fullStr}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mojtaba Michael |
