我正在查询数据库,而recordID是一个整数。当我回显$content['recordID']的值时,我有这行代码,它会打印出一个数字值,但是当我将其放入此处时,会出现此错误:


  语法错误,意外的T_ENCAPSED_AND_WHITESPACE,预期为T_STRING或T_VARIABLE或T_NUM_STRING。


但是,如果我将$content['recordID']替换为数值,它将正常工作

$sqlCommentAmount = "SELECT * FROM `info` WHERE `recordID` = $content['recordID']";

最佳答案

忽略''中的[]

... $content[recordID]";


请参阅文档示例#8:http://php.net/manual/en/language.types.string.php#language.types.string.parsing.simple

Example#8简单的语法示例

<?php
$juices = array("apple", "orange", "koolaid1" => "purple");

echo "He drank some $juices[0] juice.".PHP_EOL;
echo "He drank some $juices[1] juice.".PHP_EOL;
echo "He drank some juice made of $juice[0]s.".PHP_EOL; // Won't work
echo "He drank some $juices[koolaid1] juice.".PHP_EOL;
(...)


上面的示例将输出:

He drank some apple juice.
He drank some orange juice.
He drank some juice made of s.
He drank some purple juice.
(...)

For anything more complex, you should use the complex syntax.

关于php - 无法找出语法错误,意外的T_ENCAPSED_AND_WHITESPACE,预期为T_STRING或T_VARIABLE或T_NUM_STRING,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18324775/

10-11 23:48