0

I want to unset 1 element in the array. If for example I use GET and ?group=k

How do I unset "k" in the array?

This is the array:

$groups_array = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','a2','b2','c2','d2','e2','f2');

I have tried

   if(isset($_GET['group'])) {
     unset($groups_array[1]);
     $new_groupps_array = array_values($groups_array);
   }    

which works fine but where it shows [1] it needs to be a letter so I know how to unset it?

Hope you understand many thanks

0

2 Answers 2

0

Example, if you wanted to delete 'a' value, you simply do:

$key = array_search('a', $groups_array); // search for key of my value
if($key !== false){
  unset($groups_array[$key]);
}
0
0

Can you try this, You can use array_search function to retrieve the value based key and unset the array accordingly.

 if(isset($_GET['group'])) {          
      $key = array_search ($_GET['group'], $groups_array);
      unset($groups_array[$key ]);
      $new_groupps_array = array_values($groups_array);
  }    

Not the answer you're looking for? Browse other questions tagged or ask your own question.