Data submitted by the form user in the browser generates a graph of the diagram example.
Graphical parameter Description:
Size: The number of characters in the longest line in the graph.
Odd rows / even rows: The longest one behaves odd lines, the two adjacent rows count even rows, and so on.
Case:
A For loop is applied, and a PHP function is applied str_repeat
The Str_repeat () function repeats a string for a specified number of times.
Usage: There are two parameters,
Str_repeat (string,repeat)
stringNecessary. Specifies the string to repeat.
repeat required. Specifies the number of times the string will be repeated. must be greater than or equal to 0.
The code is as follows:
<?php/* a small effect */header (' Content-type:text/html;charset=utf8 ') of the Loop, if (!empty ($_post)) {$qi =$_post[' qi ']; $ou =$_ post[' ou ']; $count =$_post[' size '];for ($i =0; $i <= $count; $i + +) {$num 1=str_repeat ("$qi", $i). " <br> "; $num 2=str_repeat (" $ou ", $i)." <br> "if ($i%2==0) {echo $num 2;} Else{echo $num 1;}} for ($i = ($count-1), $i >= 0; $i-) {$num 1=str_repeat ("$qi", $i). " <br> "; $num 2=str_repeat (" $ou ", $i)." <br> "if ($i%2==0) {echo $num 2;} Else{echo $num 1;}}} ?> <form action= "xunhuan.php" method= "POST" > Size: <input type= "text" name= "size" style= "width:50px" > Odd rows: <input type= "text" name= "qi" style= "width:50px" > Even lines: <input type= "text" name= "ou" style= "width:50px" > < Input type= "submit" value= "Generate Graphics" > </form>
PHP Odd even loops