An explanation of the instance usage of the PHP Process Control statement

Source: Internet
Author: User
Tags case statement enterprise customer service
if (with If.. ElseIf. else extended instance) conditional statement, which executes the corresponding statement according to the given condition, is a basic statement

<?php//apply If. ElseIf. Else statement to implement the user login function of enterprise Customer service Management System $username = ' Yiciyun '; $password = ' 123456 '; if (!empty ($_post[' user ") &&!empty ($_post [' pwd ']) {    //determine if the user name and password are empty    $user =$_post[' user '];    $pwd =$_post[' pwd '];    if ($user! = $username) {                            //determine if the user name is equal to        echo ' User name error ';    }    ElseIf ($pwd! = $password) {                        //Determine if the password is equal        echo ' password error ';    }    else {                                            //If both are equal, the output login succeeds        echo ' login succeeded ';}                } else{    echo ' username or password cannot be empty ';}? >

While loop statement that loops the specified statement according to the conditions that are met until the condition is not met

Do.. The while Loop statement is basically the same as the while loop statement, unlike do: The while statement executes the specified statement once before judging

A For Loop statement that provides a more complex loop mechanism, based on the given condition loop, until the condition is not met

<?php    //99 multiplication table for ($i =1; $i <10; $i + +) {for    ($j =1; $j <= $i; $j + +) {        echo "$i * $j =". $i * $J;        echo "\ t";    }    echo "<br>";}? >

A Foreach Loop statement that is adept at working with arrays, extracting the keys and values of each cell until the end of the array

<?php//Apply the foreach statement in the loop output array of keys and values $book=array ("7 People" = "ASP Department", "5 people" = "VB Department", "6 people" = "PHP Department", "8 people" and "Java department" "), foreach ($book as $value) {    echo" $value <br/> ";} foreach ($book as $key + $value) {    echo "$key = + $value <br/>";}? >

Switch condition statement, the switch statement executes one line at a time. No code is executed at the beginning. only if the value in one case statement matches the value of the switch expression, PHP starts executing the statement until the end of the switch's program segment or the first break statement is encountered. If you do not write a break at the end of the statement segment of the case, PHP continues to execute the statement segment in the next case.

<?php    //Apply the switch statement to determine the user name and password $username = ' Mr '; $password = ' mrsoft '; switch ($_post[' user ']) {case    $ Username: $u = true; break;    Case ": echo" user name cannot be empty <br/> "; break;    Default:echo "User name error <br/>"; break;} Switch ($_post[' pwd ']) {case    $password: $p = true;    Case ": echo" password cannot be empty <br/> "; break;    Default:echo "Password error <br/>"; break;} if (Isset ($u, $p)) {    echo "login successful";}? >
<?php    //Apply switch statement to determine today is the day of the Week $week=date ("W"), switch ($week) {case    0:echo "Sunday <br/>";    Case 1:echo "Monday <br/>";    Case 2:echo "Tuesday <br/>";    Case 3:echo "Wednesday <br/>";    Case 4:echo "Thursday <br/>";    Case 5:echo "Friday <br/>";    Case 6:echo "Saturday <br/>"; >

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.