/    Sign up×
Community /Pin to ProfileBookmark

Remove value from array?

Hi,

I have try to remove a value like this:

if (isset($_SESSION[‘radera’])) {
unset ($_
SESSION[‘favoriter’][$_GET[‘radera’]]);
}

I also tried this:

$_SESSION[‘favoriter’]=array_diff($_SESSION[‘favoriter’],$_GET[‘radera’]);

When I make a request to the page I have a key value in ?radera=3, but it doesn’t work! Preciate some help! Thanks!

Perhaps there is necessary rearange the keys or values after?

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@NogDogApr 25.2010 — Hi,

I have try to remove a value like this:
[code=php]
if (isset($_SESSION['radera'])) {
unset ($_SESSION['favoriter'][$_GET['radera']]);
}
[/code]

[/QUOTE]


I see nothing wrong with that syntax, but I have no way of knowing if it is logically correct in this particular context. Also make sure you do your session_start() before that code. If that's not the issue, try echo-ing/var_dump-ing the various variables involved to see if they are truly set and have the expected values.
Copy linkTweet thisAlerts:
@criterion9Apr 26.2010 — 
?radera=3
[/quote]

Do you mean to check the _GET var instead of the _SESSION var?
Copy linkTweet thisAlerts:
@pkngauthorApr 26.2010 — Hi,

First I want to check if 'radera' is set and if 'radera' = 3, I want that it to erase the third key in the _SESSION var called 'favoriter'

?
Copy linkTweet thisAlerts:
@criterion9Apr 26.2010 — Then wouldn't you want:
[code=php]
if (isset($_GET['radera'])) {
unset ($_SESSION['favoriter'][$_GET['radera']]);
}
[/code]

instead of:

if (isset($_SESSION['radera'])) {

unset ($_SESSION['favoriter'][$_GET['radera']]);

}
[/quote]

?
Copy linkTweet thisAlerts:
@pkngauthorApr 26.2010 — Hmmmm, I think that's what I want! Thanks! ?
Copy linkTweet thisAlerts:
@criterion9Apr 26.2010 — You may also want to do some error checking and info scrubbing depending on what you are doing with the data. You might want to check that that index exists or that the value of _GET['radera'] is numeric and a non-negative number.
×

Success!

Help @pkng spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...