Parse error: syntax error, unexpected 'unset' (T_UNSET)
unset
does not return a value - it cannot be used meaningfully as an expression, even if such a production was accepted.
However, the parse error is caused because unset
is a keyword and a "special production": even though unset
looks like a function, it is not a function1. As such, unset
is only valid as a statement2 per the language grammar.
The production can be found in zend_language_parser.y:
309 unticked_statement:
| ..
338 | T_UNSET '(' unset_variables ')' ';'
1 The syntax is due to historical design choices, and arguably a mistake from a consistency viewpoint:
Note: Because [unset] is a language construct and not a function, it cannot be called using variable functions.
2 There is also "(unset) casting", but I'm ignoring that here.
Try this, Reason for unset($linkExtHelp[0])
assigning to the variable echo $totalArray =
You can't assign the unset()
value to the variable, You can use to check before unset and after unset as like below. In other words, unset
does not have any return value, since unset
is a void. Void - does not provide a result value to its caller.
Syntax: void unset ( mixed $var [, mixed $... ] )
echo "Before unset: ".$linkExtHelp[0];
unset($linkExtHelp[0]);
$linkExtHelp = array_values($linkExtHelp);
echo "After unset: ".$linkExtHelp[0];
instead of
echo $totalArray = unset($linkExtHelp[0]);