Home > Backend Development > PHP Tutorial > Several classic codes that you must collect when learning PHP Page 1/2

Several classic codes that you must collect when learning PHP Page 1/2

WBOY
Release: 2016-07-29 08:37:52
Original
1100 people have browsed it

Classic loop example


Classic loop example


for($counter = 1; $ counter <= 6; $counter++) //Loop 6 times
} {





;BODY> <br><? <BR>                                                                                                                                                                                      . <OL>n"); <br> for($currentDate = date("U"); //Define the $currentDate time format <br> date("l", $currentDate) != "Monday"; //Judge whether it is current The system time is Monday. print("<LI>" . date ("l", $currentDate) . "n"); <br> } <br> print("</OL>n"); <br>?> <br></BODY> <br></HTML> <br> Simple call of function : <br><HTML> <br><HEAD> <br><TITLE>Simple function



<
function printBold ($inputText) //Define function printBold()
{
"This business No aggravation!
n");                                                                                                                                                                                                                                                    . ("This line is not emphasized!
n"); //Print the string directly
?>



Function with return value


Function with return value



function makeBold ($inputText) //Define the function makeBold() function
                                                                                              >";
       return($ boldedText); //Return variable $boldedText
}
print("This line is not bold!!!
n"); //Print the string directly
print(makeBold("This line is bold!!! ")." & Lt; br & gt; n "); // Call the function makebold () function
Print (" This line is not worse!!!!
n"); //Print the string directly
?>



Function with default parameters

< HEAD>
"black")                                                                                                                                                                                                                   . This is the word of black color! "); // call the function function
Print (" & lt; br & gt; & lt; br & gt;"," Blue "); // Call the function function
Print (" & lt; br & gt; n "); Algorithm to determine whether it is an integer


Judge integer


Function checkInteger($Number)
{
                                                                                                                                                                                                                    
        elseif($Number                                                                                                                       * For a negative number, */
                /* You can analyze its absolute value*/
                                                                                           
                                                                                                                 }
                                                                                                                                             * According to relevant mathematical definitions */
                                                                                                                                                                                                    " ;BR>n");
print("7 is an integer? " .
checkInteger(7) . "
n");
print(" What about 3.5? " . checkInteger(3.5) . "
n");
print("What about -5?" . checkInteger(-5) . "< BR>n");
print("And -9.2?" . checkInteger(-9.2) . "
n");
?>

Initialize array


Initialize array


& lt;? " September", "October", "November", "December");
print(""May" in English is $monthName[5] .
n");//Print the 6th element in the array
?>



Get the element in the array

Get elements in the array

$monthName = array(
) /*Define $monthName[1] to $monthName[ 12]*/
1=>"January", "February", "March",
"April", "May", "June",
"July", "August", "September",
" October ", "November", "December",
/*Define $monthName["Jan"] to $monthName["Dec"]*/
"Jan"=>"January", "Feb"=>"February ",
"Mar"=>"March", "Apr"=>"April",
"May"=>"May", "Jun"=>"June",
"Jul"=> ;"July", "Aug"=>"August",
"Sep"=>"September", "Oct"=>"October",
"Nov"=>"November", "Dec" =>"December",
" /*Define $monthName["Jan"] to $monthName["Dec"]*/
"January"=>"January", "February"=>"February",
"March"=>"March", "April"=>"April",
"May"=>"May", "June"=>"June",
"July"=>"July ", "August"=>"August",
"September"=>"September", "October"=>"October",
"November"=>"November", "December"=> "December"
);
/*Print related elements*/
print("Month 5 is " . $monthName[5]. "< BR>n");
print("Month Aug is " . $monthName["Aug"] . "
n");
print("Month June is " . $monthName["June"] . "
n");
?>


Create a multidimensional array


Create a multidimensional array

         "North China" =>array(                                                                                  ​​​​
"Xi'an",
"Lhasa"
" Northern Region"][0]
?>



Current page 1/2 12Next page

The above has introduced the 1/2 pages of several classic codes that must be collected when learning PHP, including relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template