how to remove a array elements


i have a 2 d array i need to remove particular array depending on the user input

print_r($_SESSION['basket']) gives the following

Array ( [0] => Array ( [0] => SCAN ABDOMEN [1] => 120.00 [2] => 291 ) [1] => Array ( [0] => DENGUE IGG AND IGM [1] => 30.00 [2] => 178 ) [2] => Array ( [0] => OCCULT BLOOD [1] => 90.00 [2] => 153 ) )

what i need i the user will give last value i.e 291 or 178 or 153 in the array

when he gives 192 i want the entire corresponding array
 [0] => SCAN ABDOMEN [1] => 120.00 [2] => 291 to be deleted leaving the rest

similarly if he gives 178 that corresponding array....

in my case what happens is when i try deleting  3rd array 2 nd array is getting removed and when i try removing 2nd array first one is getting removed...

when when i remove the first one its getting removed properly..... in all the other cases its like as i have said above....

if ($_POST['removeItem'] != "") 
function FindBasket($id) //find product position 
		return array_search($id, $_SESSION['basket']);

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

that cause your looking for  291 or 178 or 153 and the array indexes are arrays them self,

maybe you should just search the slow way

function FindBasket($id) //find product position 
  for ($x=0, $x<sizeof($_SESSION['basket'], $x++)
    if ($id== $_SESSION['basket'][$x][2])
      return $x;
  return false;

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

try this one:
foreach ($_SESSION['basket'] as $key => $item)
    if ($item['2'] == $_POST['removeItem'])

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.