PHP Basic syntax

Source: Internet
Author: User
PHP basic syntax 1. output echo or printechoHello2. comment a single line ** multiple lines ** 3. variable loose type $ testwefwef; 4. string. connector wefwef. & nbsp ;. ewfstrlen length calculation strlen (); strpos locator strpos (helloword, wor PHP Basic syntax
1. output echo or print
Echo "Hello"

2. Notes
// Single row
/**
Multiple rows
**/

3. variable loose type
$ Test = "wef ";

4. String
. Connector
"Wef". "". "ewf"
Strlen length calculation
Strlen ("");
Strpos operator
Strpos ("hello word", "word"); // = 6 sit 0 start

5. the operators are the same as those of C and java.

6. if else and if else if have the same syntax as c and java
Switch (expression ){
Case label1:
// Code;
Break;
Default:
// Code;
} // The same syntax as c and java
}

7. array
Numeric array
$ Names = array ("one", "two", "third ");
Or
$ Names [0] = "one ";
Join array
$ Names = array ("one" => 32, "two" => 35, "third" => 45 );
Or
$ Names ['one'] = 32;
Multi-dimensional array
$ Names = array ("one" => array ("test"), "two" => 35, "third" => 45 );
Hybrid $ names = array ("one" => array ("test"), 35, "third" => 45); // echo $ names [0] 35

8. Loop
While do... while for // same as c and java syntax
Foreach
Foreach ($ array as $ vaule ){
// Assign the value in array to vaule
}

9. function
// Similar to the js function usage
Function test ($ arg1, $ arg2 ){
$ Arg3 = $ arg1. $ arg2;
Return $ arg3
}

Then
Echo test (1, 2 );

10. post
The $ _ POST variable is an array with the variable name and value sent by the http post method.

The $ _ POST variable is used to collect the values in the form from method = "post. The information sent from a form with the POST method is invisible to anyone (not displayed in the address bar of the browser) and there is no limit on the amount of information sent.

In the welcome. php
You can get value like this


11. get
Send messages up to 100 characters
Similar to post usage and directly passing parameters using URLs

In the welcome. php
You can get value like this


Why use $ _ GET?

Note: When $ _ GET is used, all variable names and values are displayed in the URL. Therefore, this method should not be used when sending passwords or other sensitive information. However, because the variables are displayed in the URL, you can add the page to favorites. In some cases, this is useful.

Note: The http get method is not suitable for large variable values. The value cannot exceed 100 characters.

12. $ _ REQUEST variable

The $ _ REQUEST variable in PHP contains $ _ GET, $ _ POST, and $ _ COOKIE content.
The $ _ REQUEST variable of PHP can be used to obtain the results of form data sent through the GET and POST methods.
Welcome .

You are Years old!



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.