可以通过附加像这样的常量变量来从数据库调用数据吗?php:用stdclass添加常量变量
$table_result->description_{constant_varible};
,使得实际stdClass的,我打算打电话是$table_result->description_B;
return '34'
;
谢谢
可以通过附加像这样的常量变量来从数据库调用数据吗?php:用stdclass添加常量变量
$table_result->description_{constant_varible};
,使得实际stdClass的,我打算打电话是$table_result->description_B;
return '34'
;
谢谢
是的,这是可能的。例如。通过$obj->{expr}
<?php
$v = 'B'; // or a constant, doesn't matter
$table_result = foo();
echo $table_result->{'description_'.$v};
function foo() {
$x = new StdClass;
$x->description_B = 34;
return $x;
}
了解它。非常感谢。 – user610983 2011-06-09 01:13:24
您的解决方案应该工作(不确定)。 这是一个备用。
$varName = 'description_'.constant_varible;
$table_result->$varName;
你应该描述你的问题得到更好的答案。现在,问题是接受“是”还是“否”作为回答 – 2011-06-08 11:08:16