If you want to find all unique 3-tuples (without distinguishing the order (e.g. [1,2,3] is the same as [2,1,3])) you can do it with 3 nested for loops. The first one begins from the first element, the second for loop begins one element further each time, and so on.
$arr = array(1, 2, 3, 4, 5);
for ($i = 0; $i < count($arr) - 2; $i++) {
$value = $arr[$i];
for($j = $i+1; $j < count($arr) - 1; $j++) {
$value2 = $arr[$j];
for($k = $j+1; $k < count($arr); $k++) {
$value3 = $arr[$k];
echo "[".$value.",".$value2.",".$value3."]\n";
}
}
}
Output :
[1,2,3]
[1,2,4]
[1,2,5]
[1,3,4]
[1,3,5]
[1,4,5]
[2,3,4]
[2,3,5]
[2,4,5]
[3,4,5]
PS : The solution pointed out in @JuanLopes duplicate's question should be preferred as it is more general.