count array value in php code example
Example 1: php length of array
<?php
$arr = ["one", "two", "three", "four"];
echo count($arr);
?>
Example 2: php count array elements with specific key
$cnt = count(array_filter($array,function($element) {
return $element['your_key']=='foo';
}));
Example 3: get array length using php
$names = array("Ankur","Raj","Ram","Suresh");
echo count($names);
Example 4: php count amount of times a value appears in array
$tmp = array_count_values($uid);
$cnt = $tmp[12];
$cnt = count(array_filter($uid,function($a) {return $a==12;}));
Example 5: php count string in array
<?php
$a[0] = 1;
$a[1] = 3;
$a[2] = 5;
var_dump(count($a));
$b[0] = 7;
$b[5] = 9;
$b[10] = 11;
var_dump(count($b));
var_dump(count(null));
var_dump(count(false));
?>