Simple Array Question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
snowrhythm
Forum Commoner
Posts: 75
Joined: Thu May 04, 2006 1:14 pm
Location: North Bay Area, CA

Simple Array Question

Post by snowrhythm »

I'm still a bit of a newbster in programming and I can't find a function that will return the amount
of elements in an array. Like if the array is...

Code: Select all

array("shake", "my", "hand", "good", "sir");
...I would want this function to return "5".

Does anyone know of a function like this? If not, I could use a little help in learning how to write
one that would do this or manipulating other functions to get that value. I tried calling array_length()
and was pretty surprised to find that it didn't exist. Anyway, thanks in advance for any help.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

Code: Select all

$amount = count ($array);
would return 5 in your case
User avatar
sweatje
Forum Contributor
Posts: 277
Joined: Wed Jun 29, 2005 10:04 pm
Location: Iowa, USA

Post by sweatje »

Spend some time looking through http://php.net/array , it will be time well spent.
User avatar
snowrhythm
Forum Commoner
Posts: 75
Joined: Thu May 04, 2006 1:14 pm
Location: North Bay Area, CA

Post by snowrhythm »

Ah yes, the great inexhaustable php function site. Thanks malcolm and sweatje, I can use all the
resources I can get my hands on.
Post Reply