0

How to create even numbers in php?

2 4 6 8 10 ------- n

7th Dec 2017, 1:22 PM
hassan
4 Antworten
+ 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; }
7th Dec 2017, 3:58 PM
David Akhihiero
David Akhihiero - avatar
+ 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
8th Dec 2017, 6:26 AM
Ammon Miranda
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.
7th Dec 2017, 3:59 PM
ABDUL MANAN
ABDUL MANAN - avatar
0
Abdul manan how can i create that in html ??
7th Dec 2017, 4:38 PM
hassan