Factors are numbers which divide the number evenly.
Factors of 12 are 1, 2, 3, 4, 6, 12
Factors ( of a number ) are numbers which when divide the number they leave 0 as reminder.
Factors using loop
We will start from 1 and continue upto half of the number. There can't be any factor of the number from half value till the number. So there is no need to check ( upper limit of the loop ) beyond the half value of the number. We may include the number itself as all numbers are devided by itself. Math modulus returns us the reminder of a division, for all factors the reminder is always 0.
$n1=50; // change this number
if($n1%$i == 0 )
echo " $i," ;
echo $n1 ;
Output is here
1, 2, 5, 10, 25,50
Using sticky form
Learn more about sticky form here. User will enter a number and the factors of the number will be displayed on submit.