count elements in an array code example
Example 1: php length of array
<?php
$arr = ["one", "two", "three", "four"];
echo count($arr);
?>
Example 2: get array length using php
$names = array("Ankur","Raj","Ram","Suresh");
echo count($names);
Example 3: Count elements in an array
const countOccurrences = (arr, val) => arr.reduce((a, v) => (v === val ? a + 1 : a), 0);
console.log(countOccurrences([1, 1, 2, 1, 2, 3], 1));
console.log(countOccurrences([1, 1, 2, 1, 2, 3], 2));
console.log(countOccurrences([1, 1, 2, 1, 2, 3], 3));