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

Jul 29, 2016 am 08:37 AM
gt lt nbsp print title

Classic loop example
<HTML>
<HEAD>
<TITLE>Classic loop example</TITLE>
</HEAD>
<BODY>
<?
for($counter = 1; $ counter <= 6; $counter++) //Loop 6 times
} {

</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE> ;BODY>
<?
                                                                                                                                                                                      . <OL>n");
for($currentDate = date("U"); //Define the $currentDate time format
date("l", $currentDate) != "Monday"; //Judge whether it is current The system time is Monday. print("<LI>" . date ("l", $currentDate) . "n");
}
print("</OL>n");
?>
</BODY>
</HTML>
Simple call of function :
<HTML>
<HEAD>
<TITLE>Simple function</TITLE>
</HEAD>
<BODY>
<FONT SIZE=5>
<
function printBold ($inputText) //Define function printBold()
{
"This business No aggravation! <BR>n");                                                                                                                                                                                                                                                    . ("This line is not emphasized!<BR>n"); //Print the string directly
?>
</FONT>
</BODY>
</HTML>
Function with return value
<HTML>
<HEAD>
<TITLE>Function with return value</TITLE>
</HEAD>
<BODY>
<FONT SIZE=5>
<?
function makeBold ($inputText) //Define the function makeBold() function
                                                                                              >";
       return($ boldedText); //Return variable $boldedText
}
print("This line is not bold!!!<BR>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!!!!<BR>n"); //Print the string directly
?>
</SIZE>
</BODY>
</HTML>
Function with default parameters
<HTML>
< 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
<HTML>
<HEAD>
<TITLE>Judge integer</TITLE>
</HEAD>
<BODY>
<?
Function checkInteger($Number)
{
                                                                                                                                                                                                                    
        elseif($Number                                                                                                                       * For a negative number, */
                /* You can analyze its absolute value*/
                                                                                           
                                                                                                                 }
                                                                                                                                             * According to relevant mathematical definitions */
                                                                                                                                                                                                    " ;BR>n");
print("<B>7 is an integer?</B> " .
checkInteger(7) . "<BR>n");
print("<B> What about 3.5? </B>" . checkInteger(3.5) . "<BR>n");
print("<B>What about -5?</B>" . checkInteger(-5) . "< BR>n");
print("<B>And -9.2?</B>" . checkInteger(-9.2) . "<BR>n");
?>
</BODY&gt ;
</HTML>
Initialize array
<HTML>
<HEAD>
<TITLE>Initialize array</TITLE>
</HEAD>
<FONT SIZE=5>
& lt;? " September", "October", "November", "December");
print(""May" in English is <B> $monthName[5] </B>.<BR>n");//Print the 6th element in the array
?>
</FONT>
</BODY>
</HTML>
Get the element in the array
<HTML&gt ;
<HEAD>
<TITLE>Get elements in the array</TITLE>
</HEAD>
<?
$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"=&gt ;"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 <B>5</B> is <B>" . $monthName[5]. "</B>< BR>n");
print("Month <B>Aug</B> is <B>" . $monthName["Aug"] . "</B><BR>n");
print("Month <B>June</B> is <B>" . $monthName["June"] . "</B><BR>n");
?>
</ BODY>
</HTML>
Create a multidimensional array
<HTML>
<HEAD>
<TITLE>Create a multidimensional array</TITLE>
</HEAD>
<? $Cities =array(                // Two-dimensional array array ()
         "North China" =>array(                                                                                  ​​​​
"Xi'an",
"Lhasa"
" Northern Region"][0]
?>
</BODY>
</HTML>

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.


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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Solution: Your organization requires you to change your PIN Solution: Your organization requires you to change your PIN Oct 04, 2023 pm 05:45 PM

Solution: Your organization requires you to change your PIN

How to adjust window border settings on Windows 11: Change color and size How to adjust window border settings on Windows 11: Change color and size Sep 22, 2023 am 11:37 AM

How to adjust window border settings on Windows 11: Change color and size

How to change title bar color on Windows 11? How to change title bar color on Windows 11? Sep 14, 2023 pm 03:33 PM

How to change title bar color on Windows 11?

How to enable or disable taskbar thumbnail previews on Windows 11 How to enable or disable taskbar thumbnail previews on Windows 11 Sep 15, 2023 pm 03:57 PM

How to enable or disable taskbar thumbnail previews on Windows 11

OOBELANGUAGE Error Problems in Windows 11/10 Repair OOBELANGUAGE Error Problems in Windows 11/10 Repair Jul 16, 2023 pm 03:29 PM

OOBELANGUAGE Error Problems in Windows 11/10 Repair

What are the differences between Huawei GT3 Pro and GT4? What are the differences between Huawei GT3 Pro and GT4? Dec 29, 2023 pm 02:27 PM

What are the differences between Huawei GT3 Pro and GT4?

Display scaling guide on Windows 11 Display scaling guide on Windows 11 Sep 19, 2023 pm 06:45 PM

Display scaling guide on Windows 11

10 Ways to Adjust Brightness on Windows 11 10 Ways to Adjust Brightness on Windows 11 Dec 18, 2023 pm 02:21 PM

10 Ways to Adjust Brightness on Windows 11

See all articles