PHP Statements and Time functions

Source: Internet
Author: User
Tags echo date

Statement

1. Branch statements

(1) if
Example:
$a = 9;
$b = 5;
if ($a > $b)
{
echo $a. " than ". $b." Large ";
}
Else
{
echo $a. " than ". $b." Small ";
}
(2) If...else ...
(3) If...else If...else
(4) If the nesting
(5) Switch: Case:
Example:
$c = 2;
Switch ($c)
{
Case 1:
echo "11111";
Break

Case 2:
echo "22222";
Break


Case 3:
echo "33333";
Break

Case 4:
echo "44444";
Break

Case 5:
echo "55555";
Break

}


2. Circular statements

(1) For loop

for ($e =0; $e <10; $e + +) {}//$ Don't forget to write


(2) While loop

Function:

1. Four elements: function name parameter function body return type

How to define in C # or Java
public void Main (int a,int b)
{
function body;
}

function Main ()
{
echo "Hello";

}

Mixed:var can write any type of
String: Fixed type
[] can write, also can not write
$... Can write any number of

Common functions:
1, random number generation: rand (1,100); can have two parameters, two integers, limit the range of random numbers
2. Function of date and time:
Time (): Takes the current datetime, is a UNIX timestamp
Date (): Requires a parameter (formatted string) that can be directly taken out of the current datetime and formatted to display
Date (), two parameters, formatted to display data of any datetime type

echo Date ("Y year M D Day H:i:s");//Complete recommendation

3. Modify the default time zone:
Found in PHP config file php.ini date.timezone = europe/paris change Europe/paris to Etc/gmt-8

<?PHP$a=9;$b=5;if($a>$b){    Echo $a." than ".$b." Big; }Else{    Echo $a." than ".$b." Small; }$c=2;Switch($c){     Case1:Echo"11111";  Break;  Case2:Echo"22222";  Break;  Case3:Echo"33333";  Break;  Case4:Echo"44444";  Break;  Case5:Echo"55555";  Break; } for($e= 0;$e<10;$e++)//$ don't forget to write{    Echo"This is the first."$e." Secondary cycle <br/> "; }$f=0; while($f<10){    Echo"This is the while loop out code <br/>"; $f++; ;}EchoMain ();functionMain () {Echo"Hello"; };EchoMain1 ("World");functionMain1 ($name){    Echo"Hello".$name; };EchoMain2 (6);functionMain2 ($a 1){    if($a>5)    {        return"This is greater than the"; }    Else    {        return"This is less than the"; }};? ><br/><?PHPEcho Rand(1,10); Echo"<br/>"; Echo  Time(); Echo"<br/>"; Echo Date("Y year M D Day H:i:s:ms", Time());Echo"<br/>"; Echo Date("Y year M D Day H:i:s:ms", Time());Echo"<br/>"; Echo Date("Y year M month D Day H:i:s:ms");//requires parameter, string, date format parameter         Echo"<br/>"; Echo  Time();//takes the current datetime, is a UNIX timestamp          Echo"<br/>"; Echo Date(""); Echo"<br/>"; Echo Date("Y year M month D Day H:i:s");//Full /*Y represents the year, the last two Y represents the year all m represents the month m for the month the abbreviation D represents the day d for the English week of Shorthand h for the hour, 12 Hour system h for the hour, the 24 hour system I for minutes s for seconds Several ms for milliseconds*/?>
Code

PHP Statements and Time functions

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.