Jump to: navigation, search

Php sizeof

From w3cyberlearnings

Contents

PHP function sizeof

This function counts the element of an array.

Syntax sizeof

  • array: array input
  • mode: 0 (default, not consider multidimensional array), 1 (treat array as multidimensional array)
sizeof(array, mode);

Example 1

<?php

$name = array('Taylor',
	 'Lucas',
	 'Makayla',
	 'Jennifer');

$size = sizeof($name);

echo "There are {$size} people in the group.";
?>


Output

There are 4 people in the group.

Example 2


<?php
$team = array(
	 'group 1'=> array('Jennifer','Nevaeh','Elizabeth'),
	 'group 2'=> array('Grace','Lauren','Chase'),
	 'group 3'=> array('Kimberly','Jade')
);

$count = sizeof($team,1);

echo $count;
?>



Output

11


Example 3

<?php

$team = array(
	 'group 1' => array('Jennifer', 'Nevaeh', 'Elizabeth'),
	 'group 2' => array('Grace', 'Lauren', 'Chase'),
	 'group 3' => array('Kimberly', 'Jade')
);

$count = sizeof($team, 1); // get all elements

$group = sizeof($team, 0); // get only the group

$players = $count - $group; // get all the players
echo "There are {$group} groups, and there are {$players} players.";
?>


Output

There are 3 groups, and there are 8 players.

Related Links


Navigation
Web
SQL
MISC
References