Table of 2 using for loop in php w3schools
PHP for LoopThe Show The PHP for LoopThe Syntax for (init counter; test counter; increment counter) { Parameters:
ExamplesThe example below displays the numbers from 0 to 10: Examplefor ($x = 0; $x <= 10; $x++) { Try it Yourself » Example Explained
This example counts to 100 by tens: Examplefor ($x = 0; $x <= 100;
$x+=10) { Try it Yourself » Example Explained
PHP ExercisesPHP foreach LoopThe The PHP foreach LoopThe Syntax foreach ($array as$value) { For every loop iteration, the value of the current array element is assigned to $value and the array pointer is moved by one, until it reaches the last array element. ExamplesThe following example will output the values of the given array ($colors): Example$colors = array("red", "green", "blue", "yellow"); foreach ($colors as $value) { Try it Yourself » The following example will output both the keys and the values of the given array ($age): Example$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43"); foreach($age as $x => $val) { Try it Yourself » You will learn more about arrays in the PHP Arrays chapter. PHP program to print table of a number: The below program prints table of a number using a loop. The PHP echo statement is used to output the result on the screen. DOCTYPE html>
<html>
<body>
php
$num = 9;
for($i=1; $i<=10; $i++)
{
$product = $i*$num;
echo "$num * $i = $product" ;
echo ' Output 9 * 1 = 9 9 * 2 = 18 9 * 3 = 27 9 * 4 = 36 9 * 5 = 45 9 * 6 = 54 9 * 7 = 63 9 * 8 = 72 9 * 9 = 81 9 * 10 = 90 Please Share How do you use a loop in a table?Algorithm. Step 1: Enter a number to print table at runtime. Step 2: Read that number from keyboard. Step 3: Using for loop print number*I 10 times. // for(i=1; i<=10; i++) Step 4: Print num*I 10 times where i=0 to 10.
How do you create a loop in a table?var table = document. createElement('table'), tr, td, i; for (i = 0; i < 220; i++) { if (i % 22 == 0) { // every 22nd cell (including the first) tr = table. appendChild(document. createElement('tr')); // add a new row } td = tr.
How can I print 1 to 10 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 fetch data from for loop in PHP?Follow the steps to fetch data from the Database in PHP PDO:. Create Database: Create a database using XAMPP, the database is named “geeksforgeeks” here. ... . Create Table: Create a table named “fetch_record” with 2 columns to store the data. ... . Create Table Structure: The table “fetch_record” contains 2 fields.. |