NYCPHP Meetup

NYPHP.org

[nycphp-talk] Removing one element from an array

David Krings ramons at gmx.net
Tue Jul 10 06:43:54 EDT 2007


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 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

Thanks, I'll try that out as well and probably use it. The array is 
numerically indexed and the pointer is an integer.
If I understand this right, my approach would then work on any array and 
any pointer. Good to know as well. :)

David



More information about the talk mailing list