本文介绍了php对象名称中带有点的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有mysql表,其中包含"operation.date","operation.name"等列.用$mysqli->fetch_object()将该表数据作为对象获取后,我得到了此信息(行的print_r):

I have mysql table with collumns like 'operation.date', 'operation.name' and etc.After fetching that table data as object with $mysqli->fetch_object() i get this (print_r of row):

stdClass Object
(
[id] => 2
[operation.date] => 2010-12-15
[operation.name] => some_name
)

如何访问operation.dateoperation.name以及所有其他奇怪命名的对象属性?

how do I acces operation.date and operation.name and all other weirdly named object properties?

推荐答案

在SQL查询中指定别名,例如SELECT column AS nameWithoutDots ...
或使用$object->{'operation.name'}
访问这些属性或将对象强制转换为数组,如下所示:$obj = (array)$obj; echo $obj['operation.name'].

Specify aliases in your SQL query like SELECT column AS nameWithoutDots ...
or access these properties with $object->{'operation.name'}
or cast the object to array like this: $obj = (array)$obj; echo $obj['operation.name'].

这篇关于php对象名称中带有点的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 10:03