PHP Process Control _php Tutorial

Source: Internet
Author: User
If statement, switch statement, while loop, Do...while Loop, for Loop, Foreach Loop, break interrupt loop, continue instruction. This is demonstrated by the week function below.

Three kinds of Process control structure of program

1. Sequential structure
2. Select structure
3. Cyclic structure

The results are as follows

The code is as follows Copy Code
$d =date ("D");
if ($d = = "Tue")
echo "Today is Tuesday";
Else
echo "Today is not Tuesday";
?>

The day of the week can be judged by an array.

The execution results should be as follows

The code is as follows Copy Code

$srttime =date ("W", Time ());
$array =array (' Day ', ' one ', ' two ', ' three ', ' four ', ' five ', ' VI ');
$todaytime =date ("Y year M D day week {$array [$srttime]}", Time ());
Echo $todaytime;
?>

1. if (condition i) {

?⑹?/p>

}



IF-1


$a = 100;
if ($a = = 100) {
echo "A is 100.";
}
?>

Or

if (condition i) {

? ⑹ Flounder?/p>

} else {

? ⑹ Nightmares?/p>

}



IF ... ELSE-1


$a = 120;
if ($a < 100) {
echo "A was small than 100.";
}
else {
echo "A was big than 100.";
}
?>

 



IF ... ELSE-2


$file = "Files.txt";
if (file_exists ($file)) {//?z. N Case exists
echo "?" N Case files.txt?
";
ReadFile ($file); The case of "n"? Heat br/>}
else {
echo "O this? N case
";
}
?>


Or

if (condition i) {

? ⑹ Flounder?/p>

} elseif {

? ⑹ Nightmares?/p>

} elseif {

? ⑹ Asher?/p>

}

...........

else {

? ⑹?

}



IF ... ELSEIF ... ELSE-1


$a = 100;
$b = 200;
if ($a > $b) {
echo "A is bigger than B";

} elseif ($a = = $b) {
echo "A is equal to B";

} else {
Print "A is smaller than B";
}
?>


2. while (condition one) {//Condition Akita???

? ⑹ Flounder?/p>

}



While


$a = 1;
while ($a < 10) {
echo "$a
";
$a + +;
}
?>

 

3. Do {

?⑹?/p>

} while (condition); Condition? Akita???



Do.. WHILE-1


$a = 1;
do {
echo "$a
";
$a + +;
} while ($a < 10)
?>

 

4. for (initial condition; Tong trampling? ⑹? {

?⑹?/p>

}



For-1


for ($a = 1; $a < $a + +)
{
echo "$a
";
}
?>


5. Break//in baiting?



Break


$ABC [0] = ' 0 ';
$ABC [1] = ' 1 ';
$ABC [2] = ' 2 ';
$a = 0;
while ($a < 4)
{
if ($abc [$a] = = ' 2 ') {//Akita? while ()? circle
Break
}
echo "$a";
$a + +;
}
?>


6. Continue//In the baiting? Circle, jump to the circle???? Next time



CONTINUE


for ($i =10; $i >1; $i-) {
if ($i = = 2) {//If the Akita??? Next time for ()? Circle
Continue
}
echo "$i
";
}
?>


7. Switch (condition) {
Case ' case ' value 1 ':
⑹ Flounder? nbsp; The case value is the same, part of the ⑹? Stopped until a break was encountered.
Break
Case ' case ' value 2:
⑹ nightmares br/> break;
............
Default
? ⑹?
Break

}




SWITCH


Switch ($i) {
Case 0:
echo "I equals 0";
Case 1:
echo "I equals 1";
Case 2:
echo "I equals 2";
}
?>


 



Switch-switch


Switch ($a) {
Case ' 1 ':
echo "one";
Break
Case ' 2 ':
echo "the other";
Break
Case ' 3 ':
echo "three";
Break
Case ' 4 ':
echo "Four";
Break
Case ' 5 ':
echo "Five";
Break
Default
echo "ZERO";
Break
}
?>

Precautions

A semicolon is added to the PHP syntax at the end of each instruction, but after the partial-end symbol} is not preceded by a semicolon.
On the part of the process separator symbol, is used {as part of the beginning, with} as the end, and C language is the same. However, C can define begin as the beginning, end end (like Pascal), and PHP cannot do this special definition.

http://www.bkjia.com/PHPjc/629020.html www.bkjia.com true http://www.bkjia.com/PHPjc/629020.html techarticle If statement, switch statement, while loop, Do...while Loop, for Loop, Foreach Loop, break interrupt loop, continue instruction. This is demonstrated by the week function below. Three processes of the program ...

  • 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.