3
05/11/2024 8:26 am
Topic starter
You are given a number num. Write a PHP script that multiplies the number by 2 and prints the result. The input comes as a parameter named num.
Examples:
1 Answer
2
05/11/2024 8:27 am
- In case the form was submitted and the input parameter num exists, take its value as integer using the function intval(string).
- Then, just print the results: echo $n * 2.
The code:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>First Steps Into PHP</title> </head> <body> <form> N: <input type="text" name="num"/> <input type="submit"/> </form> <?php if (isset($_GET['num'])) { $n = intval($_GET['num']); echo $n * 2; } ?> </body> </html>