Basic PHP Learning

Source: Internet
Author: User

1 Types of PHP tags

PHP files, if you want to use PHP syntax, you must speak the PHP language in the markup. PHP supports the following four kinds of marking methods;
①<?php?> This is the official PHP recommendation of the wording, but also our main use of the wording! This tag can be inserted anywhere in the HTML document;
>>> Note: If the page, only the PHP language, the recommended omission to end the expression '?> ',
Cause: If you include the end symbol, you may import the last extra line of the file when you import the PHP file.
②<script language= "PHP" ></script> long markup notation. This notation is always available. However, we do not recommend.
③<?> short mark style. The default does not turn on, you need to modify the php.ini file "Short_open_tag = on" open. However, because of conflicts with tags in XML, it is not recommended;
④<%%> ASP style. The default does not turn on, you need to modify the php.ini file "asp_tags = on" open. However, because of conflicts with ASP and JSP tags, it is not recommended.

2 instruction separators in PHP

The "struct definition statement" (branch, loop, class, function, and so on) in 1.php does not need to end with a semicolon.
The "function execution statement" in 2.PHP, without the end of {}, must use a semicolon very much.
3. Exception: End tag > Last statement before, you can omit the semicolon.

3 Variables in PHP

The variables in ①php, declared and used, must have a $ start.
②php is a weak type language, the variable momentum does not need to declare, you can assign any type of value directly to the variable;
③php can be used in the same time as the case of multiple variables of life,
Eg:num1=num2=num3 and cannot be separated by commas

4 Common variable functions
PHP files, if you want to use PHP syntax, you must speak the PHP language in the markup. PHP supports the following four kinds of marking methods;
unset (): Delete and release variables
Isset (): Detects if the variable is set
Empty (): detects if the variable is empty (not set or null is empty)

5 Naming of variables

Only alphanumeric underscores can be made, starting with numbers. And the variables in PHP are case-sensitive, $Name $name are different
However, PHP built-in functions or class names are case insensitive!eco Echo is valid!

6 data types in PHP (8 kinds)

4 Standard Types: Boolean boolean shaping integer floating-point float/double string
2 composite types: Arrays Array Objects Object
2 Special types: resource resource null

7 the case of false in PHP

1.Boolean false
2. Shaping 0
3. Float type 0.0
4. String "" "0" ("0.0" "000" are all pairs)
5. Empty array
6. Empty objects are counted as false only in PHP4. Other version objects are counted true
7.null the undefined variable on the monk
8. All resources are right, (except PHP4, all objects are counted)

8 Declaration of strings in PHP

PHP supports three ways of declaring strings:
① ':
② "":
③<<<--> (delimiter): $str = <<<s--> (bound identifier)
Delimiter declaration character go, start with <<< (bounding identifier)
Encounter shelf bound identifier end!! A space can not have!!!
The bounding identifier can make any letter, just to ensure the start and end of the same.
S;--> (delimitation identifier of the shelf)
④ three ways to differentiate:
A. Delimiter function, the default is the same as double quotation marks.

B. A variable cannot be parsed in single quotation marks. Both quotation marks and delimiters can parse variables.
Note: When parsing a variable with double quotes, be aware that the variable name needs to be separated by a space with other characters, or the variable is wrapped with {}.
Eg: "Hahaha${name}haha" "hahaha{$name}haha" are available.

C. Double quotation marks can be placed in single quotation marks, and double quotation marks can enclose single quotation marks. But you can not put the same type of quotation marks;

D. The escape character can be used in the middle of single quotation marks (except the single quotation mark ' itself, escape character \ itself '), and the escape characters may be used in double quotation marks.
  

9 pseudo-Types in PHP

Pseudo-type: Not a real data type. His presence is simply to tell the programmer what kind of data to make. Often used when writing help documents;
Mixed: representative parameter can make many different data types;
Number: Represents the parameter can be integer or float;
Callback: Represents a parameter that can make a callback function.

Data type conversions in PHP

1, automatic type conversion: Boolean, NULL, when representing an operation Types such as String are automatically converted to an integer or float type
 null-->0 true-->1 false-->0
 string to a number before the numeric character, not to 0& nbsp "123a"-->123 "A123"-->0

2, coercion type conversion "forces a variable to be converted to a variable of another type according to our needs."
  ① uses () to declare a new type of strong turn:

    New variable = (new type) $ original variable; $str = (string) 1;
  //new type, To use the whole product, you can also use Sao. The types of Integer/int Boolean/bool
     can be cast are as follows:
    (int), (integer)-Convert to integral type   
(BOOL), (Boolean)-Convert to Boolean
    (float), (double), (real)-convert to floating-point
(String)-Convert to String
(array)-Convert array
(object)-Convert to Object

  ② using SetType (); function strong:
 bool setType (mixed var,string type); The first parameter represents any type of variable, the second parameter represents the data type of the string type, and returns a Boolean result.
   
 ③ The difference between the two conversions:
   ①, which assigns the converted result to a new variable,
  The first ②, directly modifies the data type of the original variable.
 

Common functions for judging variable types in PHP

  Is_bool (): Determine if it is Boolean
             is_int (), Is_integer (), and Is_long (): Determines whether it is an integral type.
            is_float (), is_double (), and Is_real (): Determines whether it is a floating-point type
             is_string (): Determine if it is a string
             is_array (): Determines whether an array of
            is_object () : Determines whether the object is
            is_resource (): Determines whether it is a resource type
            is_null (): Determine if NULL
             is_scalar (): Determine if scalar
            is_numeric () : Determines whether it is any type of numeric and numeric string
            is_callable (): Determines whether a valid function name
 

Comments in PHP

Single-line Comment
/* Multiline Comment */
# Script Comments

Constants in PHP

1, the definition of the constant: bool Define (String constant name, mixed constant value [, BOOL is case-sensitive])

2, the constant attention matters;
① constant definition, only if define () function;
② constant names, which in principle require the use of uppercase declarations. Must not carry the $ symbol;
After the ③ constant is declared, the default global scope is valid. There is no scope to say;
④ constants can not be changed, and can not be deleted! Unset,settype and other functions are invalid;
⑤ constants are case-sensitive by default!!! However, you can set the define third parameter to TRUE when you declare a constant, which is not case sensitive. ,
⑥ constants must be defined with define () before they can be used. If used as a declared constant, the default is converted to a constant string. However, you will be warned.
Var_dump (NUM); --->string "NUM"
The value of the ⑦ constant, which can only be a scalar boolean String FLoat Integer

3. You can use Echo constant ("NUM"), read the constant value, and note ""!!!!
You can use Get_defined_constants () to get all the defined constants!! Includes system-customized n-Multiple constants.

Basic PHP Learning

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.