简体   繁体   English

如何将对象与箭头运算符和自定义变量结合起来

[英]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:我正在使用 Laravel 8,我需要将一个对象与箭头运算符连接起来,然后连接一个自定义变量,如下所示:

$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.所以基本上,在表products我有一个列名product_attr_correction并且它已经有一个值。

But the result of dd($product->$fullStr) return null incorrectly.但是dd($product->$fullStr)的结果返回null不正确。

But when I do dd($product->product_attr_correction) , I get the proper result value.但是当我做dd($product->product_attr_correction)时,我得到了正确的结果值。

So the question is, how can I combine an object with an arrow operator and then a custom variable properly?所以问题是,如何将对象与箭头运算符和自定义变量正确组合?

使用此语法:

$product->{$fullStr}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM