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

Khandad Niazi picture Khandad Niazi · Jan 30, 2014 · Viewed 19.9k times · Source

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.

Answer

Krish R picture Krish R · Jan 30, 2014

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]);