count函数里加函数_PHP count()函数与示例
count函數(shù)里加函數(shù)
PHP count()函數(shù) (PHP count() function)
"count() function" is used to get the total number of elements of an array.
“ count()函數(shù)”用于獲取數(shù)組元素的總數(shù)。
Syntax:
句法:
count(array, [count_mode])Here,
這里,
array is the name of an input array
array是輸入數(shù)組的名稱
count_mode is an optional parameter and it's default value is 0, it has two values
count_mode是一個(gè)可選參數(shù),默認(rèn)值為0,它有兩個(gè)值
0 – It does not count all elements of a multidimensional array
0 –不計(jì)算多維數(shù)組的所有元素
1 – It counts all elements of a multidimensional array
1 –計(jì)算多維數(shù)組的所有元素
Examples:
例子:
Input:$arr1 = array("101", "102", "103", "104", "105");Output:arr1 has 5 elementsPHP code: Using single dimensional array
PHP代碼:使用一維數(shù)組
<?php $arr1 = array("101", "102", "103", "104", "105");$arr2 = array("Amit", "Abhishek", "Prerana", "Aleesha", "Prem");$len = count($arr1);print ("arr1 has $len elements\n");$len = count($arr2);print ("arr2 has $len elements\n"); ?>Output
輸出量
arr1 has 5 elements arr2 has 5 elementsPHP code: Using multidimensional array
PHP代碼:使用多維數(shù)組
<?php $students = array("101" => array("name" => "Amit","age" => 21,),"102" => array("name" => "Abhi","age" => 20,));$len = count($students);print ("count value = $len (count_mode is not provided)\n");$len = count($students, 0);print ("count value = $len (count_mode is set to 0)\n"); $len = count($students, 1);print ("count value = $len (count_mode is set to 1)\n"); ?>Output
輸出量
count value = 2 (count_mode is not provided) count value = 2 (count_mode is set to 0) count value = 6 (count_mode is set to 1)翻譯自: https://www.includehelp.com/php/count-function-with-example.aspx
count函數(shù)里加函數(shù)
總結(jié)
以上是生活随笔為你收集整理的count函数里加函数_PHP count()函数与示例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 最小跳数
- 下一篇: __str__是什么函数_PHP str