NYCPHP Meetup

NYPHP.org

[nycphp-talk] Removing one element from an array

Dell Sala dell at sala.ca
Mon Jul 9 22:56:17 EDT 2007


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 of lines with  
array_splice.


> Nevertheless, I am intrigued by array_slice, but I guess I postpone  
> understanding that until tomorrow.

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 context might look like this:

array_splice($_SESSION['sessiondisplay'], $_SESSION 
['sessionviewpointer'], 1);

This would only makes sense if $_SESSION['sessiondisplay'] is a  
numerically indexed array, and if $_SESSION['sessionviewpointer'] is  
an int.

-- Dell




More information about the talk mailing list