PHP Study Notes (2)-syntax and Data Type

Source: Internet
Author: User

I. Basic data Syntax of PHP

1. Mixed HTML and PHP programming.

For example:

 
<! Doctype BR public "-// W3C // dtd html 4.01 transitional // en" "http://www.w3.org/TR/html4/loose.dtd"> <HTML>  

3. Each PHP statement ends with a semicolon ).

 
<? PHP $ STR = "a wonderful PHP world !!! "; // End with a semicolon echo $ STR; // end with a semicolon?>

3. How to define a variable and how to use the variable

1) variable definition must begin with the $ symbol.

2) the variables are defined as follows:

<? PHP $ _ = 100; // $ _ start to define echo $ _; echo "<br/>"; $ _ A = "a100 "; // $ _ connect to the lower-case letter echo $ _ A; echo "<br/>"; $ _ A = "Z100"; // $ _ connect to the upper-case letter echo $ _; echo "<br/>"; $ _ A = "abcabc100"; // $ _ connect the echo $ _ A; echo "<br/> "; $ _ 2 = "200"; // $ _ connect to a large number echo $ _ 2; echo "<br/>"; $ A = "A200 "; // $ connect to lower-case letters echo $ A; echo "<br/>"; $ A = "A200"; // $ connect to upper-case letters echo $; echo "<br/>"; $ aa100 = "aa100"; // $ echo $ aa100; echo "<br/> "; // $100 = 100; this method is incorrect // echo $100;?>

4. php comments

1) single line comment: // comment the content of a single line

2) multi-line comment:/* Comment on multi-line content */

 
<? PHP $ username = "admin"; // define the username variable as "admin" $ Password = "888 "; /* define the value of the password variable to "888" * // ** define the array variable * loop input to display the array content **/$ arrystr = array ("A" => 2, "B" => 4, "C" => 6, "D" => 8, "E" => 1 ); foreach ($ arrystr as $ k = >$ value) {echo "$ k = >$ value <br/> \ n" ;}?>

Ii. php data operation type

1) Four scalar types

Boolean (Boolean)

Integer)

Float (float type is also "double ")

String (string)

 
String: use $ to declare the custom variable $ abc = "how are you? "; Display value: <? PHP $ abc = "how are you? "; Echo $ ABC;?> <Br/> INTEGER: Declares the integer type $ number = 100. displayed value: <? PHP $ number = 100; echo $ number;?> <Br/> Boolean: Boolean Type $ isok = true; displayed value: <? PHP $ isok = true; echo $ isok;?> <Br/> foat: floating point type: $ f_number = 10.00123123; displayed value: <? PHP $ f_number = 10.00123123; echo $ f_number;?> <Br/>

2) Two composite types

Array)

Arry: array type: $ arrynumber = array (9, 8, 6, 4, 2, 1); display value: <? PHP $ arrynumber = array (9, 8, 6, 4, 2, 1); foreach ($ arrynumber as $ value) {echo "value: $ value <br/> \ n" ;}?> <Br/> arry: array type: $ arrystr = array ("A" => 2, "B" => 4, "C" => 6, "D" => 8, "E" => 10); displayed value: <? PHP $ arrystr = array ("A" => 2, "B" => 4, "C" => 6, "D" => 8, "E" => 1); foreach ($ arrystr as $ k => $ value) {echo "$ k => $ value <br/> \ n" ;}?> <Br/>

Object)

 
Object: Object Type: $ userobj = new userinfo <? PHP class userinfo {function getuser () {echo "username: lhj588 <br/> Email: lhj588@live.cn" ;}}$ userobj = new userinfo; echo $ userobj-> getuser ();?>

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.