php将字符串附加到stdClass对象
我正在从数据库中提取记录,并且有一个名为 content_fr
的文件 _fr
是根据站点语言动态创建的。
从表中获取所有记录当然会给我 content_fr
字段。我需要做的是手动分配此 case _fr
中的后缀,如果我尝试连接 $row->content.'_fr'
我收到错误 注意:未定义的属性:stdClass::$content
,这是有道理的,因为 $content 不存在,但 $content_fr
存在。使用标准数组,我可以像 $row['content_fr'] 那样执行此操作,并且工作正常,但现在使用 stdClass 我收到错误。
如何将 $row->content.'_fr'
转换为一个字符串,以便 php 将其视为 $row->content_fr
?
I'm pulling records from database, and I have a filed called content_fr
the _fr
is being dynamicaly created based on a site language.
Getting all records from the table gives me of course content_fr
field. What I need to do is manually assign the suffix in this case _fr
if I try to concatenate $row->content.'_fr'
I get the error Notice: Undefined property: stdClass::$content
, which makes sense since $content does not exist, but $content_fr
does. Using standard arrays I was able to do it like $row['content_fr']
, and worked fine, but now using stdClass I'm getting an error.
How can I convert $row->content.'_fr'
into one string, so that php sees it as $row->content_fr
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这样:
Try it like this :
您可以按如下方式进行操作:
编辑:顺便说一句,这个问题已在这里被问过很多次。请参阅以前的线程,例如这个: 访问对象的属性,例如如果对象是数组。
You can do it as follows:
EDIT: By the way, this question has been asked here many times. See previous threads such as this one: Accessing object's properties like if the objects were arrays.
尝试这样的事情:
Try something like this: