Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
集成每个循环和MySql变量关联数组_Mysql_Arrays_Variables_For Loop - Fatal编程技术网

集成每个循环和MySql变量关联数组

集成每个循环和MySql变量关联数组,mysql,arrays,variables,for-loop,Mysql,Arrays,Variables,For Loop,下面这一行是for-each循环的一部分,该循环通过从SQL查询返回的关联数组进行循环。我得到这个错误: 可捕获的致命错误:无法转换类stdClass的对象 插队 当我为$field2使用指定的变量时,会发生错误。但是,如果我用表中的实际字段名替换$field2,即country\u slug,它会起作用 如何在下面的语句中使用变量 echo "<a href='/dealers/3/$geography->$field2/'>$geography->county_sh

下面这一行是for-each循环的一部分,该循环通过从SQL查询返回的关联数组进行循环。我得到这个错误:

可捕获的致命错误:无法转换类stdClass的对象 插队

当我为
$field2
使用指定的变量时,会发生错误。但是,如果我用表中的实际字段名替换
$field2
,即
country\u slug
,它会起作用

如何在下面的语句中使用变量

 echo "<a href='/dealers/3/$geography->$field2/'>$geography->county_short</a>"
echo“”
正如迈克尔所说

使用
{}
作为
{$geography->$field2}

但您的线路中存在另一个错误。您缺少结束语句的结束分号。

您的线路应如下所示:


echo”“

{}
中的内容括起来,作为
{$geography->$field2}
我想你的意思是
echo”“。谢谢你解决了这个问题。声明中的{是什么意思?