Php5 and mysql5web development technology-3 Variable, expression, and constant _ PHP Tutorial

Source: Internet
Author: User
Tags constant definition scalar
Php5 and mysql5web development technology-3 variables, expressions, and constants. 1. define, name, and classify scalar variables, array variables, and objects. 2. print and output the echo statement printf () function example :: printf (% dbootlesofbeon 1. define, name, and category

It can be divided into scalar variables, array variables, and objects.

2. print and output variables

Echo statement

Printf () function

Instance ::

Printf ("% d bootstrap Les of beer on % s", 100, "the wall ");

Printf ("The % 2 \ $ s liks to % 1 $ s", "bark", "dog ");

Sprintf () function

Instance:

$ Formatted = fprintf ("% 01.2f", $ var );

3. display arrays and objects

Print_r (array and variable );

Var_dump (array \ variable \ object)

Var_export (array \ variable \ object) can return the expression of a variable by setting parameters.

Instance:

$ V = var_export ($ a, true); // return the php source code, which is directly used in the php script array.

4. Data types supported by php variables

Integer, double precision, positive, Boolean

Array, object, Resource)

NULL

Two methods to reference strings: double quotation marks and single quotation marks

Get and set the variable type: gettype ()/settype ()

Arrays and objects are called conforming data types.

5. variables

$ Var_name = 'php5 ';

$ Var_name = ''php5 web development details;

Echo $ php5;

6. Super global variable array

$ _ GET []

$ _ POST []

$ _ COOKIE []

$ _ SESSION []

$ _ ENV []

$ _ SERVER []

$ _ FILES []

$ _ REQUEST []

$ _ GLOBALS []

7. variable operators

The content is large, and only the types are not listed in detail.

Arithmetic

Assignment

String connection

Addition and subtraction of front and rear

Variables with the same memory address after Reference and reference assignment

Ternary operators

Comparison

Boolean operator

Bitwise operators

Other operators:

1. error suppression @

2. external command execution

$ Out = · dir c :·

Print_r ($ out );

$ Our = shell_exec ("dir ");

Echo $ out;

The results of the two functions are the same. put the results in an array. the shell_exec () method places the results in a scalar variable.

8. variable and step-by-step processing

Isset ()

Unset ()

Empty ()

Is_array () \ is_integer () \ is_numeric ()

9. Data Conversion

Force type conversion of variables:

(Array)

(Bool)/(boolean)

(Int)

(Object)

(Real)/(double)/(fload)

(String)

Others:

(1) intval ($ var ):

(2) HereDoc

HereDoc allows you to embed large text content in php, such as an email template or html or text content.

$ String = 'hello ';

$ Output = <

The value of \ $ string in HEREDOC is $ string.

MYDOC

Echo $ output;

Output result: $ string in HEREDOC is hello.

(3) conversion character

\ N, \ t, \, \ $ ,\''

(4) numeric conversion functions

Chr ($ var): returns the corresponding ASCII characters based on the value of $ var;

Ord ($ string) returns the ASCII value of the first character of the string;

10. constant definition and magic constant

Define ("CONSTANT_NAME", constant value)

_ LINE __

_ FILE __

_ FUNCTION __

_ CLASS __

_ METHOD __

Examples include scalar variables, array variables, and objects. 2. printf () function example of the echo statement of the print and output variables: printf (% d bootles of beer on...

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.