ArrayObject::count()函数是PHP中的内置函数,用于获取ArrayObject中公共属性的数量。
用法:
int ArrayObject::count( void )
参数:该函数不接受任何参数。
返回值:此函数返回ArrayObject中公共属性的数量。
以下示例程序旨在说明PHP中的ArrayObject::count()函数:
示例1:
// PHP program to illustrate the
// ArrayObject::count() function
// Declare an array and convert it
// into array object
$arrObject = new ArrayObject(
array('Geeks', 'for', 'Geeks')
);
// Use ArrayObject::count() function
// to count the number of public
// properties in the ArrayObject
$count = $arrObject->count();
print_r($count);
?>
输出:
3
示例2:
// PHP program to illustrate the
// ArrayObject::count() function
// Declare an associative array
$arr = array(
"a" => "Welcome",
"b" => "to",
"c" => "GeeksforGeeks"
);
// Create into array object
$arrObject = new ArrayObject($arr);
// Use ArrayObject::count() function
// to count the number of public
// properties in the ArrayObject
$count = $arrObject->count();
print_r($count);
?>
输出:
3