Computer Science, asked by Shivamjain6769, 1 year ago

Write a program in php to genrate first 20 numbers from 1 to 20

Answers

Answered by VedaantArya
0

<?php

for($i = 1; $i <= 20; $i++) {

echo $i.PHP_EOL;

}

?>

The variable $i is, in PHP, initialized along with its declaration in the for-loop. The loop then begins, executing until $i is equal to 20, incrementing it by one after printing it each time, along with an endline (PHP_EOL: breaks the line in output). I would've used ."<br" if I was sure that the output is as HTML, and not in commandline (PHP can also be used to build CLI stuff, so).

Similar questions