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;
我是 php 新手,我无法弄清楚如何将确切的字符串“ <?php”输出为 HTML 字符串、从文件(即file_get_contents(blah);)输出或echo "<?php";在代码段内输出。我认为它被解释为 php 代码段的开头,因为没有输出数据。任何帮助,将不胜感激。
<?php
file_get_contents(blah);
echo "<?php";