To create a set of integers in PHP, you can use an array or the SplObjectStorage class.
In this example,
integers
containing integers.<?php
$integers = [1, 2, 3, 4, 5, 5];
$intSet = array_unique($integers);
print_r($intSet);
?>
Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 )
In this example,
<?php
$intSet = new SplObjectStorage();
$intSet->attach(1);
$intSet->attach(2);
$intSet->attach(3);
$intSet->attach(4);
$intSet->attach(5);
foreach ($intSet as $integer) {
echo $integer . ' ';
}
?>
1 2 3 4 5
In this tutorial, we learned How to create a Set of integers in PHP language with well detailed examples.