PHP Program to find Number Combination

Last Updated:

Find Number Combination

In the following example, we will find all possible combinations of numbers with 4 and 8 within the limit 500.

Example

PHP Compiler
<?php $combination = 2; $num = array(4, 8); $limit = 500; echo "List of combinations of 4 and 8 upto 500: <br>"; // Iterate from 1 to limit for($i=1; $i<=$limit; $i++) { $copyNum = $i; $count = 0; $flag = 0; // Check each digit starting from last digit while($copyNum != 0) { $count++; $lastDigit = $copyNum % 10; for($j=0; $j<$combination; $j++) { if($num[$j] == $lastDigit) $flag++; } $copyNum = floor($copyNum / 10); } // result if($count == $flag) echo "$i "; } ?>

Share this Page

Meet the Author