$maxArray = [5, 10, 7, 18, 3];
[
[0, 0, 0, 0, 0],
[1, 0, 0, 0, 0],
[2, 0, 0, 0, 0],
...
[5, 0, 0, 0, 0],
[0, 1, 0, 0, 0],
[1, 1, 0, 0, 0],
[2, 1, 0, 0, 0],
...
[5, 1, 0, 0, 0],
[0, 2, 0, 0, 0],
[1, 2, 0, 0, 0],
[2, 2, 0, 0, 0],
...
[5, 10, 7, 18, 3]
]
<?php
$maxArray = [5, 10, 7, 18, 3];
$result = [];
for($i4 = 0; $i4 <= $maxArray[4]; $i4++) {
for($i3 = 0; $i3 <= $maxArray[3]; $i3++) {
for($i2 = 0; $i2 <= $maxArray[2]; $i2++) {
for($i1 = 0; $i1 <= $maxArray[1]; $i1++) {
for($i0 = 0; $i0 <= $maxArray[0]; $i0++) {
$result[] = [$i0, $i1, $i2, $i3, $i4];
}
}
}
}
}
echo join(',', $result[0])."\n";
echo join(',', $result[1])."\n";
echo join(',', $result[2])."\n";
echo join(',', $result[3])."\n";
echo join(',', $result[40127])."\n";
//0,0,0,0,0
//1,0,0,0,0
//2,0,0,0,0
//3,0,0,0,0
//5,10,7,18,3