Jump to content

[SOLVED] Remove an item from an array?


Solarpitch

Recommended Posts

Hey,

 

I have the floowing code to add an id to an array but how can I remove an id from the array if I needed?

 

<?php

	$id = $_GET['id'];

	if(!is_array($_SESSION['compare']))
	{
	  $_SESSION['compare'] = array();
	  }

	if(!in_array($id, $_SESSION['compare']))
	{
	  $_SESSION['compare'][] = $id;
	}


?>

Link to comment
https://forums.phpfreaks.com/topic/135818-solved-remove-an-item-from-an-array/
Share on other sites

Thanks but I already did. See, I'm using unset in the below context but instead of removing the id, it removes all of the id's which I cant find the solution to on that page

 

<?php

unset($id, $_SESSION['compare']);

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.