Re: [nyphp-talk] Removing one element from an array

2007-07-10 Thread David Krings
Dell Sala wrote: I think you want array_splice, not array_slice. array_splice removes a section of an array an optionally replaces it with another array. It resets the keys of the array if it is numerically indexed. In your case, you leave out the replacement argument. An example in your con

Re: [nyphp-talk] Removing one element from an array

2007-07-09 Thread Dell Sala
On Jul 9, 2007, at 10:22 PM, David Krings wrote: Cliff Hirsch wrote: Look at array_slice Based on the vote tally array_slice won, but I don't get this command. I just went for broke and tried my unset suspicion and indeed it works. Your solution seems fine to me. You just save a couple

Re: [nyphp-talk] Removing one element from an array

2007-07-09 Thread David Krings
Cliff Hirsch wrote: Look at array_slice Based on the vote tally array_slice won, but I don't get this command. I just went for broke and tried my unset suspicion and indeed it works. This is the scenario: I have abunch of record IDs in an array, which I stuffed into the $_SESSION variable. T

Re: [nyphp-talk] Removing one element from an array

2007-07-09 Thread Cliff Hirsch
Look at array_slice ___ New York PHP Community Talk Mailing List http://lists.nyphp.org/mailman/listinfo/talk NYPHPCon 2006 Presentations Online http://www.nyphpcon.com Show Your Participation in New York PHP http://www.nyphp.org/show_participation.ph

Re: [nyphp-talk] Removing one element from an array

2007-07-09 Thread Jon Baer
Hmmm (not sure why Im always trying to compact stuff to one line now) ... $array = array(1,2,3,3,3,3,4,5); $remove = 3; while (in_array($remove, $array)) unset($array[array_search($remove, $array)]); print_r(array_values($array)); - Jon On Jul 9, 2007, at 8:16 PM, David Krings wrote: Hi!

Re: [nyphp-talk] Removing one element from an array

2007-07-09 Thread Graham Hagger
Hi David, Ran into this myself a short time ago. There's probably a better answer, but I ended using array_diff. Basically I pass in the original array, and a new single element array containing the element to remove, and pocket the difference. To (kinda) rewrite the manual/online help fo

Re: [nyphp-talk] Removing one element from an array

2007-07-09 Thread Dell Sala
take a look at array_splice() -- Dell On Jul 9, 2007, at 8:16 PM, David Krings wrote: Hi! I have an array with numerical keys. I need to remove one element of the array and then rekey the array to have consecutive keys again. I got the rekeying down, but how do I pop off an array eleme

[nyphp-talk] Removing one element from an array

2007-07-09 Thread David Krings
Hi! I have an array with numerical keys. I need to remove one element of the array and then rekey the array to have consecutive keys again. I got the rekeying down, but how do I pop off an array element in the middle of an array? Is that done using unset($array[123]) ? I'm having a deer-stari