To get a sub Set in PHP, you can use the array_slice function.
In this example,
mySet
containing elements of a specific type.array_slice
function with the specified range to get the sub Set.<?php
// Define array with items
$mySet = ['apple', 'banana', 'orange', 'grape', 'melon'];
// Get sub Set with items
$subSet = array_slice($mySet, 1, 3);
echo 'Sub Set with items: ' . json_encode($subSet);
?>
Sub Set with items: ["banana","orange","grape"]
In this example,
mySet
.<?php
// Define empty array
$mySet = [];
// Get sub Set from empty array
$subSet = array_slice($mySet, 1, 3);
echo 'Sub Set from empty array: ' . json_encode($subSet);
?>
Sub Set from empty array: []
In this tutorial, we learned How to get Subset from a Set in PHP language with well detailed examples.