Is there a function to count an array?

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
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Is there a function to count an array?

Post by impulse() »

For example:

Code: Select all

while ($i = 0; $i > 50; $i++) {
  $a[$i] = 0;
  }
How would I cound the array to output 50?

Stephen,
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Just a thought... taking a wild stab in the dark... maybe.. hmmm: count() ? ;)
brendandonhue
Forum Commoner
Posts: 71
Joined: Mon Sep 25, 2006 3:21 pm

Post by brendandonhue »

I think this is what you wanted for your loop:

Code: Select all

for ($i = 0; $i < 50; $i++)
{
//Do something here
}
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

Yes!, I remember now! I've been messing with 'while' for the past few days so I forgot it was a for loop. Thank you.
brendandonhue
Forum Commoner
Posts: 71
Joined: Mon Sep 25, 2006 3:21 pm

Post by brendandonhue »

No problem, you might want to look at both of these by the way as I'm not entirely sure which one you're trying to get.

Code: Select all

for ($i = 0; $i < 50; $i++)
{
echo $i . '<br>';
}

Code: Select all

for ($i = 0; $i <= 50; $i++)
{
echo $i . '<br>';
}
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

I would recommend a good read through the manual sections on Arrays and Strings for the basics.
(#10850)
Post Reply