RE: [PHP] how to judge the end of a array?
| From: | Lawrence dot Sheed at dfait-maeci dot gc dot ca | Date: | Mon, 20 Nov 2000 09:42:48 +0000 |
| Subject: | RE: [PHP] how to judge the end of a array? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-26224@lists.php.net to get a copy of this message | ||
http://www.php.net/manual/function.sizeof.php
sizeof:
Caveat;
Note that sizeof($x), where $x is a variable that is set but is not an array
sizeof, returns 1. Hence you have to be careful e.g. when you are dealing
with arrays of multiple dimensions.
for ($i = 0; $i < sizeof($myarray[$j]); $i++) will not work as expected if
$myarray[$j] hasn't been assigned a value (i.e. an array value).
Another way:
end($yourArray);
$index = key($yourArray);
for ($i=0;$i<$index;$i++) {
...
}
cheers,
lawrence.
-----Original Message-----
From: forestwater [mailto:forestwater@sina.com]
Sent: November 20, 2000 05:44 PM
To: php-general@lists.php.net
Subject: [PHP] how to judge the end of a array?
I use the following source to judge the end of a array
while ($my_array[$i++][$j]!=null)
for($j=1;$j<=5;$j++)
{
echo($my_array[$i][$j]);
echo("\n<br>");
}
but the IE refering:"Undefined offset: 6 "
so how can judge the end of a array
thanks
______________________________________
===================================================================
ÐÂÀËÃâ·Ñµç×ÓÓÊÏä http://mail.sina.com.cn
ÐÂÀËÍÆ³ö°ÂÔ˶ÌÐÅÏ¢ÊÖ»úµã²¥·þÎñ
http://sms.sina.com.cn/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net