This is probably a very stupid question, but I am totally stuck:
I would like to delete an element from an array, not just give it a value of "" (nothing). Is that possible, and if yes, how?
Thanks a lot!
Johannes
| SitePoint Sponsor |
This is probably a very stupid question, but I am totally stuck:
I would like to delete an element from an array, not just give it a value of "" (nothing). Is that possible, and if yes, how?
Thanks a lot!
Johannes

If you know which element you want to delete, use array_splice. Example :
(you can't use array_splice in PHP3)Code:$a = array("A","B","C","D","E"); // to remove 'D' array_splice($a,3,1); // now $a contain "A","B","C","E"
Well, that's a problem, my host doesn't offer php4 yet...(you can't use array_splice in PHP3)
Is there any known way with php3?
Johannes





Check out the documentation in http://www.php.net about array
I'm sure you could, but I'm sorry, I started with php4 right away, dunno how to do in php3 (maybe pop/shift?!)
![]()
- Son Nguyen
AdSpeed.com - Ad Serving and Ad Management Made Easy

array_pop and array_shift also added in PHP4. If you know which element you want to remove I guess you can try this :
It should work.Code:$k = 0; $flag = 0; for($i=0; $i<count($old_array); $i++) { /* loop for each element you want to remove (put them in $match array) */ for($j=0; $j<count($match); $j++) { if($old_array[$i] == $match[$j]) { $flag = 1; /* if match, set flag to 1 */ break; } } /* keep it if it's not the one to remove */ if($flag == 0) $new_array[] = $old_array[$i]; }
Bookmarks