Get the size of an array in PHP using the count() function : count « Data Structure « PHP






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)); 
?>
  
  








Related examples in the same category

1.Counting Array Elements
2.Getting the Number of Lines in a File
3.Using count() to Iterate Through an Array