Skip to content
Advertisement

Parse error: syntax error, unexpected ‘unset’ (T_UNSET)

I am using simple php unset() function to remove and index of array but it’s showing the following error:

Parse error: syntax error, unexpected 'unset' (T_UNSET)

Here is my erroneous code:

echo $totalArray = unset($linkExtHelp[0]);

Thanks in advance.

Advertisement

Answer

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]);
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement