PHP Odd even loops

Source: Internet
Author: User
Tags rows count

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.