dolythgoe
asked on
Deleting a value from an array
Hi all,
I have an array stored in a $_SESSION. I'm trying to remove an element but it doesn't seem to be working.
The array is a list of ids in no particular order like array(12453, 23123, 23424, 43535, 64334) etc..
How do I delete an entry with a matching value? Like from the above example, remove 23424.
Cheers
I have an array stored in a $_SESSION. I'm trying to remove an element but it doesn't seem to be working.
unset($_SESSION['favorite_link_array'][$link_id]);
The array is a list of ids in no particular order like array(12453, 23123, 23424, 43535, 64334) etc..
How do I delete an entry with a matching value? Like from the above example, remove 23424.
Cheers
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Cheers guys - Ray, professional as always :)
Yes, they are indeed unique values.
So populating your later example, would that be something like:
Yes, they are indeed unique values.
So populating your later example, would that be something like:
while($row=mysqli_fetch_array($result))
{
$favorite_link_array[$row['link_id']] = $row['link_id'];
}
Yes, that looks right to me.
$newArray = remove_item_by_value($myAr
I guess... are you sure $_SESSION['favorite_link_a
in that case, you can use replace function, or split it make array, remove one item and then join the array to make it a string again and put into session back as string...
$_SESSION['favorite_link_a
but php supports array in session, so using it as array will make life easier...
http://stackoverflow.com/questions/2306159/array-as-session-variable
your code looks fine as long as yo have a valid array in session...
Open in new window