Nesting your loops is the trick. Try the following example. I've replaced your while-loops by foreach-loops with the PHP range function, and nested (i.e. loop-inside-a-loop) them inside eachother:
function colourArray($number) {
$colours = array();
foreach(range(0,$number) as $r) {
foreach(range(0,$number) as $g) {
foreach(range(0,$number) as $b) {
$colours[] = array($r,$g,$b);
}
}
}
return $colours;
}
References: