0
How to create even numbers in php?
2 4 6 8 10 ------- n
4 Answers
+ 8
Create?
something like this for exampkr;
function even(){
$even_nums = array();
for($i = 0, $j = 0; $i <= 100; $i+=2, $j++){
$even_nums[$j] = $i
}
return $even_nums;
}
+ 2
I guess it all depends on how you're going to use the result but you can always create a function/statement and using the modulo operator (%) to test for remainders when dividing by 2. It can be in a for loop, while loop, anything you want; if x%2==0, it's even
0
$n=$_GET[ 'num']; //Take input from the HTML field
for(x=2; x<=n; x+2)
{
print x;
}
Here n is the highest element in the series you want to print.
0
Abdul manan how can i create that in html ??