【发布时间】:2022-11-15 11:57:33
【问题描述】:
我从数据库中拉出一行,我想通过动态变量访问它
$prop = "theProp";
$test0 = $row["theProp"]; // Works fine
$test1 = $row->{$prop}; // Doesn't work
$test2 = $row->$prop; // Doesn't work
我到处看了看,显然做了一些愚蠢的事情,请有人赐教。
【问题讨论】:
-
像任何其他数组一样使用
$row[$prop]。你为什么使用->?