SoFunction
Updated on 2025-04-13

Bad Wolf's PHP Learning Tutorial Day 3, Page 2/2


2. Multiple lines else if
example:

 <?php
 $a = 4;
If($a > 5)   //No need to add a semicolon here, pay attention!
    {
    echo "a > 5\n";
    }
    else  if($a > 3)    
    {
    echo "a > 3\n";
    }   
    else      
    {
    echo "a < 5\n";
    }
?>


3. Omitting method

 <?php
 $a = 4
 $a > 5 ? $str = "a > 5" : $str = "a < 5" : $str = "a = 5";
 echo $str;
?>




While back to circle (Quick Memories English: Bad Mate) Although
(condition1 condition)
{  statement1
 statement2
if(condition2 condition)
   break
 statement3
}

Terminate and break the regulations.
Stop 1 line and continue running.
() Leaving is not necessarily used here, it is very commonly used.


do ...while Do it at least once

do
{
 staement1
    ↓
 staement2
 }
while(condition)
If the condition condition is true, the program in do will be returned.

example

 <?php
    do
 {
   echo $w."<br>";
   $w++;
 }
 while($w<10)
?>




FOR Back to the Circle

example

 <?php
for($o=;$o<100;$o++)//There is no semicolon at the end.
 {
 echo $o."<br>\n";
 }
?>



Each word in the foreach array is completed. Array (array)


 <?php
$MyArray1 = arry("bad wolf", "good guy", "bad guy", "hehe");
$MyArray1 = arry("1" => "Good person","2" => "Bad person");  //Represents "xxx1" => "Good person",
?>


Learn this first, and then learn tomorrow... I feel a little dizzy... I practice it more if I have time...
 
Copy the codeThe code is as follows:

<html> 
 <head> 
<title>Bad Wolf Learning PHP Day 3</title>
 <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
 </head> 
 <body> 
<?php  
$a= "10";  //Connect the right side to the left side
$a+=”2”;  //Add the right side to the left side
echo $a."<br>\n";  //The result here is 12, which roughly means that $a is equal to 10, and then 2 is added to the left (that is $a), so it is 12.
/* No matter what $a represents, it roughly means right to left. "Connect to" or "add to" or "subtract to", etc. */
$b = "Bad Wolf";   //There are several key points that you must remember!; The semicolon should be written, ""It is best to add quotation marks.
$b.= "Great person!";
$b.= "Great person!";
echo $b."Haha!\n";
?> 
 <br>   
<?php 
$a= "65896255618562314793123219";  //The calculation is complicated here, it turns out that php processing is simple here!
$a/= "465342233234234"; //Let these 2 numbers be multiplied!
echo $a."←This is the result! 65896255618562314793123219 divided by 465342233234234, ordinary people are not as quick as arithmetic! Haha @!\n"
?> 
 <br> 
<?php 
@include("");  //If it does not exist, an error will be reported, but it will not be displayed after adding @!
   echo "<br>\n"; 
?>   
<br><br><br> 
<?php 
 $a = 4.998; 
If($a > 5)    //No need to add a semicolon here, pay attention!
    { 
echo "By the way!a > 5\n";
    } 
else       //No need to add a semicolon here, pay attention!
    { 
echo "Wrong!a < 5\n";
    }    
?>           
<br><br><br> 
<?php 
 $a = 4; 
If($a > 5)    //No need to add a semicolon here, pay attention!
    { 
    echo "a > 5\n"; 
    } 
    else  if($a > 3)     
    { 
    echo "a > 3\n"; 
    }    
    else       
    { 
    echo "a < 5\n"; 
    } 
?>     
<br><br><br> 
<?php 
 $a = 4; 
 $a > 5 ? $str = "a > 5" : $str = "a < 5"; 
 echo $str; 
?> 
<br><br><br> 
<?php 
 $p = 0; 
 while ($p<20) 
{   

 echo $p."<br>"; 
 $p++; 
if($p==15)break; //Terminate here to break this regulation.

?> 
<br><br><br> 
<?php 
 $p = 0; 
 while ($p<20) 
{   
 $p++; 

if($p==15)continue; //Stop here and continue

 echo $p."<br>"; 

?> 
<br><br><br> 
<?php 
$w = 999; //If you remove this display 1.2...19
    do 
 { 
   echo $w."<br>"; 
   $w++; 
 } 
 while($w<20) 
?> 

<br><br><br><br><br><br> 
<?php 
for($o=0;$o<100;$o++)  //There is no semicolon at the end.
 { 
 echo $o."<br>\n"; 
 } 
?> 

 </body> 
</html> 
Previous page12Read the full text