A naive approach would be to increment a variable from 12345
till 98765
and to select it only if it has unique digits and sum of digits is 30
:
for($i=12345;$i<98765;$i++) { $arr = preg_split('//',strval($i)); if(count(array_unique($arr)) == count($arr) && array_sum($arr) == 30) echo $i."\n";}