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

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


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


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.


You can't assign "unset". this is how I do.you need to make a temp array.

 $totalArray  = $linkExtHelp; // assign it to a new array (so you can keep the original one ) foreach ($totalArray  as $key => $value) { unset($totalArray  [$key]['save_day']); // if you need to remove all of 'save_day' value from multi array } var_dump($totalArray); // after unset var_dump($linkExtHelp); // the original array //echo $totalArray  =     unset($linkExtHelp[0]); // This is wrong. no echo

I hope it helps.