简体   繁体   中英

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; you must use unset($player[$x]); .

unset is a function, you need to call it with parentheses, like this: 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]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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