This site is mobile accessible. Press the "Tap Here" button to use a different font-size.


Smartphone icons created by Freepik - Flaticon

PHP Arrays

count() Function

Normal count: 3
Recursive count: 8

<?php
// define a multidimensional array
$cars=array
   (
   "Volvo"=>array
   (
   "XC60",
   "XC90"
   ),
   "BMW"=>array
   (
   "X3",
   "X5"
   ),
   "Toyota"=>array
   (
   "Highlander"
   )
   ); 

// "normal" count and display the number of elements of the main array
echo "Normal count: " . count($cars)."<br>";

// count all the elements, including the sub-arrays
echo "Recursive count: " . count($cars,1);
?>