Re: [PHP] How To Get Last Item Of An Array?

2002-12-25 Thread Leon Mergen

"John W. Holmes" <[EMAIL PROTECTED]> schreef in bericht
000401c2ac54$142032c0$7c02a8c0@coconut">news:000401c2ac54$142032c0$7c02a8c0@coconut...
> Kind of begs the question of why can't you just select what you need
> with the proper query, instead of loading everything into an array...

Yeah, just add limit 0,1 desc to the query



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] How To Get Last Item Of An Array?

2002-12-25 Thread Jason Wong
On Thursday 26 December 2002 03:34, Chris Wesley wrote:
> On Wed, 25 Dec 2002, @ Nilaab wrote:
> > I have an multi-dimensional array called $cat_data, which is info
> > extracted from a MySQL DB. I want to retrieve the very last item of that
> > array. How would I do that? I know the first item can be retrieved by
> > simply asking for $cat_data[0][0], which contains an id number. But I
> > can't figure out how to get the last item in that same array --
> > $cat_data[x][0] where x is the last item in the array.
>
> Naturally, the index of last item of an array is one less than the total
> number of elements in the array.
>
> $num_elements = count( $cat_data );
> $last_element = $cat_data[$num_elements-1][0];
> // 0 being what you were seeking

Or, if you don't need to keep $cat_data intact, you can use array_pop().

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

/*
When it is not necessary to make a decision, it is necessary not to
make a decision.
*/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] How To Get Last Item Of An Array?

2002-12-25 Thread John W. Holmes
> I have an multi-dimensional array called $cat_data, which is info
> extracted
> from a MySQL DB. I want to retrieve the very last item of that array.
How
> would I do that? I know the first item can be retrieved by simply
asking
> for
> $cat_data[0][0], which contains an id number. But I can't figure out
how
> to
> get the last item in that same array -- $cat_data[x][0] where x is the
> last
> item in the array.

Kind of begs the question of why can't you just select what you need
with the proper query, instead of loading everything into an array...

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] How To Get Last Item Of An Array?

2002-12-25 Thread Chris Wesley
On Wed, 25 Dec 2002, @ Nilaab wrote:

> I have an multi-dimensional array called $cat_data, which is info extracted
> from a MySQL DB. I want to retrieve the very last item of that array. How
> would I do that? I know the first item can be retrieved by simply asking for
> $cat_data[0][0], which contains an id number. But I can't figure out how to
> get the last item in that same array -- $cat_data[x][0] where x is the last
> item in the array.

Naturally, the index of last item of an array is one less than the total
number of elements in the array.

$num_elements = count( $cat_data );
$last_element = $cat_data[$num_elements-1][0];
// 0 being what you were seeking

Cheers!
~Chris



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] How To Get Last Item Of An Array?

2002-12-25 Thread @ Nilaab
Hello Everyone,

I have an multi-dimensional array called $cat_data, which is info extracted
from a MySQL DB. I want to retrieve the very last item of that array. How
would I do that? I know the first item can be retrieved by simply asking for
$cat_data[0][0], which contains an id number. But I can't figure out how to
get the last item in that same array -- $cat_data[x][0] where x is the last
item in the array.

P.S. - I read the section on Arrays at php.net, but unfortunately I didn't
find my answer there. I also checked my PHP books, no mention of my problems
there either.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php