0

I'm trying to remove one value in array and I'm using Unset function, but when I'm passing array in Unset function I got error.

array:

Array ( [mid] => 8 [optionsRadios2] => 0 [optionsRadios3] => 1 [optionsRadios5] => 0 [optionsRadios6] => 0 [optionsRadios7] => 1 [optionsRadios24] => 0 [optionsRadios25] => 1 )

I want to remove mid and I'm using like this:

$module=$data['mid'];
$newdata=unset($data['mid']);

error:

Parse error: syntax error, unexpected 'unset' (T_UNSET) in C:\xampp\htdocs\Traning\application\controllers\home.php on line 77

Please help.

2 Answers 2

2

Use only:

unset($data['mid']);

without assign to variable.

In docs unset() return void.

Sign up to request clarification or add additional context in comments.

Comments

1

at the first look you code looks ok?

can you check this example http://sandbox.onlinephpfunctions.com/code/b538f88a23433b767005f5a16ca99faa5eb4f8b0

$koko = [
 'mid' => 1, 
 'name' => 'koko'
];

print_r($koko);

echo '---------------------------';

$toto = $koko['name'];

unset($koko['name']);

print_r($koko);
echo 'and your name is : '.$toto;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.