PHP Array Boundaries

Programming, for all ages and all languages.
Post Reply
User avatar
~
Member
Member
Posts: 1226
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

PHP Array Boundaries

Post by ~ »

I am currently designing a sort of web IDE for development, and currently I'm facing a problem in which I don't know how to get an array boundary (i.e., the account/number of how many elements it contains) for tasks such as accounting code lines, etc.

Should I use something like foreach for counting, even when it could make processing double-slow, first for accounting the elements and then for doing whatever with them, or is there some function? I haven't found yet some function like $elements=get_array_limit($myarray) which could easily return the number of elements.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

Try

Code: Select all

$size = sizeof( $myarray );
PHP's sizeof isn't the same as C's sizeof.
User avatar
B.E
Member
Member
Posts: 275
Joined: Sat Oct 21, 2006 5:29 pm
Location: Brisbane Australia
Contact:

Post by B.E »

do you mean a to find out how many elements in an arrary? if so try
count()
edit: just found out that sizeof() is an alias of count()

Code: Select all

$count = count($array);
Image
Microsoft: "let everyone run after us. We'll just INNOV~1"
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

That's why I posted sizeof...
Post Reply