NYCPHP Meetup

NYPHP.org

[nycphp-talk] Removing one element from an array

Jon Baer jonbaer at jonbaer.com
Mon Jul 9 21:03:12 EDT 2007


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!
>
> 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-staring-in-the-headlights-moment.
>
> David
> _______________________________________________
> 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.php




More information about the talk mailing list