Question: How can I print 1 to 10 numbers in PHP?

How to print1 to 10 number in php?

php $answer = ; for ($i = 1; $i <= 10; $i++){ $answer = $i + $answer; if ($i == 10) { echo $i.” = “.

How to print numbers in php?

We can print numbers from 1 to 10 by using for loop. You can easily extend this program to print any numbers from starting from any value and ending on any value. The echo command will print the value of $i to the screen. In the next line we have used the same echo command to print one html line break.

How to print even numbers in php using for loop?

php $end=50; $even= “Even Numbers Are : “; $odd=”<br /> Odd Numbers Are : “; for($i=1;$i<=$end;$i++) { if($i%2==0) { $even. =$i.”,”; }else $odd. =$i.”,”; } echo $even.

How do you echo a loop in php?

The code below uses for… each loop to read and print the elements of an array. <? php $animals_list = array(“Lion”,”Wolf”,”Dog”,”Leopard”,”Tiger”); foreach($animals_list as $array_values){ echo $array_values .

PHP For Each loop

  1. “foreach(…){ …
  2. “$array_data” is the array variable to be looped through.
IT IS INTERESTING:  You asked: How do I create a subclass in Java?

How do you sum numbers in PHP?

To find sum of digits of a number just add all the digits.


  1. <? php.
  2. $num = 14597;
  3. $sum=0; $rem=0;
  4. for ($i =0; $i<=strlen($num);$i++)
  5. {
  6. $rem=$num%10;
  7. $sum = $sum + $rem;
  8. $num=$num/10;

What is Range function PHP?

The range() function is an inbuilt function in PHP which is used to create an array of elements of any kind such as integer, alphabets within a given range(from low to high) i.e, list’s first element is considered as low and last one is considered as high. Syntax: array range(low, high, step)

What is PHP full form?

PHP (recursive acronym for PHP: Hypertext Preprocessor ) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.

How do I run a PHP file?

php” file extension. Open up any Web browser on your desktop and enter “localhost” into the address box. The browser will open a list of files stored under the “HTDocs” folder on your computer. Click on the link to a PHP file and open it to run a script.

What is the difference between print () and echo ()?

“echo and print are more or less the same. They are both used to output data to the screen. The differences are small: echo has no return value while print has a return value of 1 so it can be used in expressions. echo can take multiple parameters (although such usage is rare) while print can take one argument.

How can I get even number in PHP?

Even Odd Program in PHP

  1. <? php.
  2. $number=1233456;
  3. if($number%2==0)
  4. {
  5. echo “$number is Even Number”;
  6. }
  7. else.
  8. {
IT IS INTERESTING:  How do I open a 10 GB file in SQL?

How can I print even numbers in PHP?

To print even and odd numbers we can use different types of method. In first method we use ‘for’ loops to print even numbers between 1 to 100. Here loop starts from number 2 and after every count its value increment by 2 for print even numbers. In first method we use ‘for’ loops to print odd numbers between 1 to 100.

How can I print prime numbers from 1 to 100 in PHP?

php for($i=1;$i<=100;$i++){ for($j = 1; $j<=$i; $j++){ $temp = $i%$j; if($temp == 1){ echo “is a prime number &nbsp; “. $j.”<br>”; } } } ?>

Secrets of programming