0

PHP Function

In the school my challenge was to write a function in PHP to check if a number is odd, is true unless its false. <?PHP function numberodd($number) if($numer / 2){ echo:"The numer" $numer "is divisible"; } else{echo:"The numer" $numer "ist not divisible";} ?> numberodd(7); Is that correct?

17th Jan 2019, 6:20 PM
Mr T
Mr T - avatar
2 Answers
+ 2
1. put "{" and "}" when declaring the function 2. delete ":" after "echo" 3. instead of "/" use "%" <?PHP function numberodd($number){ if($number%2){ echo "The numer ".$number." is not divisible <br />"; } else{ echo "The numer ".$number." is divisible <br />"; } } numberodd(7); numberodd(6); ?>
17th Jan 2019, 7:58 PM
Игорь Яковенко
Игорь Яковенко - avatar
0
WoW thank you so much!
20th Jan 2019, 8:25 AM
Mr T
Mr T - avatar