Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 php 中,我从 mysql 查询结果集中访问结果,如下所示:
$results->fldname;
我的问题是如何动态地将字段名称传递给 $results?例如:
$results->fld_$name;
试试这个:
$results->{'fld_'.$name}; //or (not recommended) $name = 'fld_'.$name; $results->$name;
如果你问这在 PHP 中是否可行,那么是的:
$field = "fld_name"; $result->$field;
这将与以下内容相同:
$result->fld_name;