To get the size of a set in PHP, you can use the count
function on the set.
In this example,
$set1
using the array
function with some elements.count
function on the set $set1
to get the number of elements in the set.count
function returns the size of the set.<?php
$set1 = array('apple', 'banana', 'cherry');
$size = count($set1);
echo 'Size of set1: ' . $size;
?>
Size of set1: 3
In this example,
$emptySet
using an empty array.count
function on the set $emptySet
to get the number of elements in the set.count
function returns 0.<?php
$emptySet = array();
$size = count($emptySet);
echo 'Size of emptySet: ' . $size;
?>
Size of emptySet: 0
In this tutorial, we learned How to Get Length of a Set in PHP language with well detailed examples.