PHP Program to find Number Combination

You are Here:

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 "; } ?>

Output

List of combinations of 4 and 8 upto 500: 4 8 44 48 84 88 444 448 484 488

Reminder

Hi Developers, we almost covered 90% of String functions and Interview Question on PHP with examples for quick and easy learning.

We are working to cover every Single Concept in PHP.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author