count()
` function to return the length of an array :<?php
// Create an indexed array
$fruits = array("apple", "banana", "orange", "kiwi");
// Print the length of the array
echo "The length of the fruits array is: " . count($fruits) . "<br>";
// Create an associative array
$ages = array("John" => 25, "Mary" => 30, "Bob" => 35);
// Print the length of the array
echo "The length of the ages array is: " . count($ages) . "<br>";
?>
The length of the fruits array is: 4
The length of the ages array is: 3
count()
` function to return the length of two different arrays. The first array is an indexed array `$fruits
` with four elements. We pass this array to the `count()
` function, which returns the number `4
`.count()
` function, which returns the number `3
`.count()
` function is a built-in function in PHP that can be used to return the number of elements in an array. It works with both indexed and associative arrays.