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:[EMAIL PROTECTED]]
> Sent: Thursday, April 19, 2001 17:08
> To: Jason Caldwell
> Cc: [EMAIL PROTECTED]
> 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: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > To contact the list administrators, e-mail: [EMAIL PROTECTED]
> >
> >
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]