Mega Code Archive

 
Categories / Php / Data Type
 

Get the size of an array in PHP using the count() function

<?php      $dogs = array('A' => 'C', 'B' => 'D', 'X' => 'Z');           $birds = array('a', 'b', 'c', 'd');           printf("%d dogs and %d birds", count($dogs), count($birds));           $birds[] = 'i';      printf("%d birds:", count($birds));      printf("%s", var_export($birds, TRUE));                $birds[10] = 'h';      unset($birds[3]);      printf("%d birds:", count($birds));      printf("%s", var_export($birds, TRUE));  ?>