PHP

PHP Menu

PHP

sizeof() Function - Definition, Syntax, Parameters, Examples

Definition

The sizeof() function count all elements in an array (alias of count() function).

Syntax

sizeof(array, mode)

Parameters

Parameter Description
array Required. Specifies the array.
mode Optional. Specifies the mode. Possible values:
0 - Default. Does not count all elements of multidimensional arrays
1 - Counts the array recursively (counts all the elements of multidimensional arrays)

Example

<?php
// Example 1 $cities = array("New York", "London", "Tokyo", "Berlin", "Cairo"); echo sizeof($cities) . "<br>";
// Example 2 $persons = array( "Mark" => array(22, "USA"), "Jeff" => array(32, "JPN"), "Mike" => array(28, "RUS") ); echo sizeof($persons) . "<br>"; echo sizeof($persons, 1) . "<br>";

Introduction

PHP Basics

PHP Advance

PHP OOP

PHP Functions and Methods