ຫົວຂໍ້ PHP count() function
Example
The number of elements in the array is returned:
<?php $cars=array("Volvo","BMW","Toyota"); echo count($cars); ?>
Definition and Usage
The count() function returns the number of elements in the array.
Syntax
count(array,mode);
Parameter | Description |
---|---|
array | Required. Specifies the array. |
mode |
Optional. Specifies the mode. Possible values:
|
Description
The count() function calculates the number of units in an array or the number of properties in an object.
For arrays, returns the number of elements, for other values, returns 1. If the parameter is a variable and the variable is not defined, then returns 0.
If mode If set to COUNT_RECURSIVE (or 1), it will recursively count the number of elements in the array.
Technical Details
ກຳລັງມາອອກຈາກວິສະວະກອນ. | ກຳລັງມາອອກຈາກວິສະວະກອນ. |
PHP Version: | 4+ |
ບັນທຶກການປັບປຸງ: | mode ພຽງສະເໜີພາກສ່ວນໃນ PHP 4.2. |
ຕົວຢ່າງອື່ນໆ
ຕົວຢ່າງ 1
ການຄາດການຕົວເລກຂອງວິສະວະກອນ
<?php $cars=array ( "Volvo"=>array ( "XC60", "XC90" , "BMW"=>array ( "X3", "X5" , "Toyota"=>array ( "Highlander" ) ); echo "ການຄາດການທົດແທນ: " . count($cars)."<br>"; echo "ການຄາດການກັບຕົວເລກຂື້ນ: " . count($cars,1); ?>