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
- array_change_key_case
- array_chunk
- array_combine
- array_count_values
- array_diff_assoc
- array_diff_key
- array_diff_uassoc
- array_diff_ukey
- array_diff
- array_fill_keys
- array_fill
- array_filter
- array_flip
- array_intersect_assoc
- array_intersect_key
- array_intersect_uassoc
- array_intersect_ukey
- array_intersect
- array_key_ exists
- array_keys