简体   繁体   English

PHP:这行代码怎么了?

[英]PHP: What's wrong with this line of code?

if($player[$x]->name == $p->name || $player[$x]->name == $target) unset $player[$x]; //<-- line 215

commenting out this line removes the error: 注释掉此行可消除错误:

PHP Parse error:  syntax error, unexpected T_VARIABLE, expecting '(' in /path/script.php on line 215

But I don't see were it's expecting a (, am I missing something obvious? 但是我没有看到它是否期望(,我是否缺少明显的东西?

unset() is a language construct that requires parentheses; unset()是需要括号的语言构造; you must use unset($player[$x]); 您必须使用unset($player[$x]); .

unset is a function, you need to call it with parentheses, like this: unset( $player[ $x ] ) unset是一个函数,您需要用括号来调用它,如下所示:unset($ player [$ x])

you'd better separate your code to different lines to see where the problem is more easily. 您最好将代码分成不同的行,以更轻松地了解问题所在。

未设置需要括号:

if($player[$x]->name == $p->name || $player[$x]->name == $target) unset($player[$x]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM