Posted By

sekihin on 02/17/11


Tagged

php array


Versions (?)

delete from array


 / Published in: PHP
 

URL: http://bytes.com/topic/php/answers/7353-simple-delete-array

  1. // by the position (offset)
  2. array_splice($my_array, 1, 1);
  3.  
  4. // by the key
  5. array_splice($my_array, array_search('banana', $my_array), 1);
  6.  
  7. // if using associative arrays
  8. $my_array = array(
  9. 'apple' => 1
  10. 'banana' => 2,
  11. 'grape' => 3,
  12. 'lime' => 4
  13. );
  14. unset($my_array['banana']);

Report this snippet  

You need to login to post a comment.