RE: [PHP] Last Element in an Array?

From: Date: Fri, 20 Apr 2001 03:42:52 +0000
Subject: RE: [PHP] Last Element in an Array?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-49461@lists.php.net to get a copy of this message
you can get the amount of elements in an array using count() and use that # as an index value for 1+ the last value (the last value that's NOT IN the array) $a = array('12', '198', 'b'); print count($a); this'll give you "3", which, as you can see, the last valid subscript of $a is $a[2]; > -----Original Message----- > From: Andrew Hill [mailto:ahill@openlinksw.com] > Sent: Thursday, April 19, 2001 17:08 > To: Jason Caldwell > Cc: php-general@lists.php.net > Subject: Re: [PHP] Last Element in an Array? > > > Jason, > > You can use array_pop() to return the last element of the array - > > $last_item = array_pop ($array); > > but if you just want your array processing to stop when it's reached the > last item in the array (and avoid the loop) then do something like: > > while (list ($var1, $var2) = each ($array)) > > HTH! > > Best regards, > Andrew > -------------------------------------------- > Andrew Hill - OpenLink Software > Directory of Technology Evangelism > Internet Data Integration Technology > http://www.openlinksw.com > > On Thursday, April 19, 2001, at 07:57 PM, Jason Caldwell wrote: > > > Is there a command which will tell me that it is the last in an array? > > > > When I use END it just gives me the value IN the array... I want to know > > when I hit the last element in an array... > > > > This is driving me crazy... > > > > Thanks. > > Jason > > > > > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > > For additional commands, e-mail: php-general-help@lists.php.net > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#49461) next »