FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


get the count of first dimension of an array





badai
let say i have this 2 dimensional array

Code:
a, b, c, d, e, f
g
h, i, j, k, l
m, n, o, p
.
.
.
.
x, y, z


i don't know how many rows and how many cols in each rows. if i want to find how many cols in any row, i can use count or sizeof row[$i], but now i want to find how many rows in that array. if i use count or sizeof, it will just give me total elements in that array.

thanks.
Peterssidan
I don't know but I think the only way to do it is to iterate through all the rows to see what the most nr of columns is.
kv
If you do a count or sizeof on an array, it will give the count of the first level elements only and not the count of all elements.

For example, the below code will produce following output.

Code:

<?
//number of rows 2 with indexes 0 and 1. number of elements 4

$a[0][0]=100;
$a[0][1]=200;
$a[1][0]=300;
$a[1][1]=400;

echo count($a)."   ".sizeof($a);

?>


Output:
Code:
 
2   2   <-- 2 rows
badai
yes, i just found out about it. thanks.
Related topics
[php scripts ] phpweather&email
Interview: Derek Liu, Gaia Online Anime Community
Which Online-Games you prefer?
Fortran Tutorials(77)
Windows vs. Linux
Xtemplate - PHP Implode Code Error
The 4th Dimension
PHP Array, explode, count , access array problem.
4th dimention
some help with javascript please
PHP load array from $_POST
Array in php
Array Update SQL script not working
The Watchmaker Gambit
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.