Chapter 1 3/3 PHP syntax and data types

Source: Internet
Author: User
Tags define function echo name
Chapter 1 section 3/3 PHP syntax and data type 1. statements are divided into two types: Schema definition statements and functional execution statements. 1) structure definition statement (large arc ). Do not add points after the statement: & lt ;? Phpif () {}while () {}for (;;){}? & Gt; 2) for function execution statements, you must add a semicolon: & lt ;? Php $ a = 1.0 Chapter 1 section 3/3 PHP syntax and data types
1. there are two types of statements: Schema definition statements and functional execution statements.
1) structure definition statement (large arc ). Do not add points after the statement:
If ()
{
}
While ()
{
}
For (;;)
{
}
?>
2) to execute the function, you must add a semicolon:
$ A = 1.0;
$ B = 1.0;
Echo "aaaaaa ";
?>
3) in special circumstances, do you want to leave?> The nearest semicolon can be marked with no plus points:
Echo "aaaaaaa ";
Echo "bbbbbbbb"
?>
">


2. notes and functions:
1) single row comment
// Echo "aaaaaaaaaaaaaaa ";
2) multi-line comment
/*
Echo "bbbbbbbbbbbbbb ";
*/
3) text comments
/**
*/
4) functions of annotations:
A. You do not need to rush to delete the program you have written. comment out the program first.
B. debug the program
C. write help documents

3. variables and constants
Php is a weak language (compared with java, c ++) for the following reasons:
$ A = 100;
$ A = true;
Echo $;
The result is true.
1) the variable starts with the $ symbol.
Variables are case sensitive, and others are case insensitive, for example, $ a = 100; $ A = 200; are two variables.
2) naming rules
Do not start with a number, space, decimal point, or system keyword. The following is an incorrect expression:
$ Name. age, $ var, $4, $. 12, $ a B
3) the weak type naming standard can assign values of any type. There are eight primitive types of variables.
$ A = any type can be assigned to the end
Four scalar types:
-- Boolean
-- Integer
-- Floating point type
-- String
Two composite types
-- Array $ a = array (1, 3, 4 );
-- Object class P {var $ name;} $ a = new P ();
Two special types
--Resource export a‑fopen(‑test.txt "," w "); var_dump ($ a); the result is resource
-- Null
Retrieve type functions:
Echo getType ($ );
Var_dump ($ a); // You can view the type and data.
4) constant. there is no $ character in front of it.
A. only four scalar data types (boolean, integer, float, string) are supported)
B. The value can only be assigned at declaration and cannot be changed at runtime.
Define ("NAME", "testName ");
Echo NAME;
5) differences between variables and constants:
A. $ Character, constant does not exist, and variable has.
B. constants are defined by the define function and cannot be assigned by the value assignment statement.
C. constants can be defined and accessed anywhere without following the variable range rules.
D. Once a constant is defined, it cannot be redefined or canceled.
E. The constant value can only be a scalar.
6) check whether a constant exists. use echo defined ("NAME"). The output value is 1 to indicate that the constant NAME exists.
If (defined ("NAME "))
{
} Else {
}
Check whether the variable exists. isset ($ );
7) Common constants in PHP
Echo _ FILE __; // physical path
Echo _ LINE __; // row number
Echo _ PHP_VERSION; // the version number.
Echo PHP_ OS; // operating system

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.