PHP 语法错误,“意外的 T_VARIABLE"- isQuestion($query) [英] PHP syntax error, "unexpected T_VARIABLE" - isQuestion($query)
问题描述
代码:
public function isQuestion($query){
$questions = $this->getAllQuestions();
if (count($questions)){
foreach ($questions as $q){
if ($this->isQuestion$q($query)){
return $this->isQuestion$q($query);
}
}
}
return false;
}
错误:
解析错误:语法错误,第 7 行/Applications/XAMPP/xamppfiles/htdocs/ai/application/models/question_model.php 中的意外 T_VARIABLE
Parse error: syntax error, unexpected T_VARIABLE in /Applications/XAMPP/xamppfiles/htdocs/ai/application/models/question_model.php on line 7
问题出现在:
if ($this->isQuestion$q($query)){
return $this->isQuestion$q($query);
我有一些函数,例如 isQuestion1、isQuestion2、isQuestion3 等...我调用另一个函数 getAllQuestions 将返回数组中所有问题的数字,例如 1,2,3,4,5....
I have some functions like isQuestion1, isQuestion2, isQuestion3, etc... and I call another function getAllQuestions that will return me all the numbers of the questions in an array like 1,2,3,4,5....
然后我使用上面的代码来检查每个函数是否是基于查询的问题.
Then I use the above code to check if each function is a question based on a query.
推荐答案
好吧,以下是无效语法:
Well, the following is invalid syntax:
if ($this->isQuestion$q($query)){
试试这个:
foreach ($questions as $q) {
if ($result = $this->{'isQuestion' . $q}()) {
return $result;
}
}
return false;
这篇关于PHP 语法错误,“意外的 T_VARIABLE"- isQuestion($query)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!