0

Just a simple question - have this array:

 Array
(
    [year] => Array
        (
            [0] => 2019
 [1] => 2020
        )

    [user] => [email protected]
)

I just want to completely remove [user] => [email protected] from this Array.

The user will have always only one ocurrence.

I tried unset($filter['user'][0]); also unset($filter['user']); but nothing works.

1
  • unset should do it. Can you please post code example so we can search the error? Commented Jun 26, 2019 at 12:30

2 Answers 2

1

you can use unset

<?php


 $array = Array
(
    "year" => Array
        (
            0 => 2019,
 1 => 2020
        ),

    "user"=> "[email protected]"
);


unset($array['user']);

print_r($array);
?>
Sign up to request clarification or add additional context in comments.

2 Comments

I think that what the OP does where he said in the question unset($filter['user']); - but it still doesn't work
@ dWinder, yes, I tried the same it's working fine.
1

Actually "[user] => [email protected]" is an array index not array. You need to use this syntax

unset($array['user']);

here $array is the name of array.

1 Comment

I think that what the OP does where he said in the question unset($filter['user']); - but it still doesn't work

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.