PHP Basic Knowledge Point Summary (i)

Source: Internet
Author: User
Tags arithmetic operators echo name php language type null variable scope

First, basic syntax of PHP

PHP (hypertext preprocessor, hyper-text preprocessor) is a scripting language that runs on the server side.

1.PHP Language Tags
<?php standard style tag, which belongs to XML style;?>
<script lanauage= "PHP" > Long style Tags </script>
<? Short-style marker?>
<% ASP-style tag%>

2.PHP Instruction Separator
PHP needs to end with a semicolon after each statement (instruction)!

3. Program Notes
Single-line Comment
# single Comment
/* Multiline Comment */
/** Multi-line Document comments */

4. Variables
In short, a variable is a container for temporarily storing values. (variables are at the heart of any language)

Name of the variable:
The declaration variable in PHP must be represented by a dollar sign "$" plus the variable name followed, using the assignment operator (=) to assign a value to a variable.

Name of the variable:
A valid variable name is preceded by a letter or underscore, followed by any number of letters, numbers, or underscores. Note that the variable name must not start with a number, and the middle can not use spaces, can not use points separate and so on!

According to the normal regular expression, he will be expressed as: ' [a-za-z_\x7f-\xff][a-za-z0-9_\x7f-\xff]* '.

Variable variable:
$str = ' Hello ';
$ $str = ' world ';

echo "$str $hello";//Output Hello World
echo "$str $ $STR";//Output Hello World

A reference to a variable is assigned a value:
Simply use "&" to add to the variable that will be assigned. This means that the new variable simply refers to the original variable. (In other words, "become its alias" or "point to").
$foo = ' Bob ';
$bar = & $foo;

$bar = ' World, Hello! ‘;
echo $bar;//Output world, Hello!
echo $foo;//Output world, Hello!

$foo = ' Hello World ';
echo $foo;//Output Hello World
echo $bar;//Output Hello World

Types of variables:
  

|-----Boole Boolean Type
|-----integer Shaping
|-----Four types of scalar----|-----Float float, also called double

| |-----String String

|

Data type--|
| |-----array of arrays
|----------of two composite types |
| |-----Object Objects

| |-----Resource Resources
|-----Two special types of-----|
|-----NULL

Boolean (TRUE or FALSE):
Boolean value False
Integer value 0 is false, other non-0 values are true either positive or negative
Floating-point 0.0
Blank string and string ' 0 '
An array with no member variables
object with no cell (PHP4 only)
Special type NULL

Integer: If the given number exceeds the integer range, it will be interpreted as float.

Floating point: The range is between 1.7e-38~1.7e+38 and is accurate to 15 decimal places.

String: You can use single quotes, double quotes, and delimiters in three ways to define it!

Arrays: Multiple data can be stored, and any type of data can be deposited.

Object: Composed of properties and methods. The property represents the object state, and the method represents the object Function!

Resource type: a reference to an external resource is created and used through a dedicated function!

NULL type: null does not represent a space, does not represent zero, and does not represent an empty string, but rather a variable that has a null value.
Assign the variable directly to null;
The declared variable is not assigned a value
Variables destroyed by the unset () function

Pseudo type:
Mixed: Indicates that a parameter can accept a variety of different (but not necessarily all) types.
Number: A parameter can be an integer with the latter float.
Callback: Accepts user-defined functions as parameters.

Data types are converted to each other:

Automatic type conversion
Boolean true translates to 1,false conversion to 0.
Null is converted to 0.
Integer and floating-point operations, the integer type is automatically converted to floating point type, and then the operation
Strings and numbers participate in budgeting, and strings are converted to numbers before they are calculated.

Forcing type conversions
(int), (integer): Converted to integral type
(bool), (Boolean): Converted to Boolean
(float), (double), (real): Convert to floating-point type
(string): converted to a string
(array): Convert an array
(object): Convert to Object
Or use a specific conversion function: Intval (), Floatval (), and Strval ().
Note: integer conversion to floating point type, because its precision range is less than floating point type, so the precision will not change after conversion, but floating-point type
When converted to an integral type, its fractional portion is automatically discarded.

Detection Variable Type:
Is_bool (): Boolean type
Is_int (), Is_integer (), Is_long (): Integer type
Is_float (), is_double (), Is_real (): Floating-point
Is_string (): Whether it is a string
Is_array (): is the array
Is_object (): Whether it is an object
Is_resource (): Is a resource type
Is_null (): Is empty
Is_scalar (): Whether it is a scalar, that is, whether it is an integer, a floating-point number, a Boolean, or a string.
Is_numeric (): Whether it is any type of numeric or numeric string
Is_callable (): Determine if the function name is valid

Constants: Used for some fixed values!

Declaration of constants: constant names are still case-sensitive by using the Define () function, which, by convention, does not add "$" to the constant names until they are all capitalized.
Example:define (' NAME ', ' Xiaozhang ');

echo name;//Output Xiaozhang

The difference between a constant and a variable:
No "$" symbol before constant
Constants can only be defined by the Define () function and cannot be assigned
Constants can be defined and accessed anywhere without regard to the rules of variable scope
Constants cannot be redefined or undefined once defined, until the end of the script run is automatically released
The value of a constant can only be a scalar type

Common Magic Constants in PHP:
__FILE__: The current file name
__LINE__: Current number of rows
__FUNCTION__: the current function name
__CLASS__: The current class name
__method__: Method name for the current object

Operator
Arithmetic operators:
+ Plus
-Minus
* Multiply
/except
% take-up (modulo)
+ + Cumulative
--Fatigue reduction

Note: $a + + evaluates the expression before performing an incremental operation, and the + + $a performs an increment operation before evaluating the value of the expression. Exhaustion!

Assignment operators:
= Assign a value or expression evaluation result to a variable
+ = Assigns the result of the variable and the assigned value to the variable
-=......
*=......
/=......
%=......
. = assigns the variable to the value after it is attached to the variable

Comparison operators:
> Greater than
< less than
>= greater than or equal to
<= less than or equal to
= = equals
= = = All equals
<> or! = Range
!== not congruent
Note: the difference between = = and = = = is only concerned about whether the value of the number that participates in the comparison is equal, regardless of the type!

Logical operators:
True for and or && logic with both sides must be true
OR OR | | Logical or both sides as long as a true is true
Not OR! Logical non-inverting, if the expression is true the result is false
XOR logical XOR or both sides are not true at the same time

Expression: The cornerstone of PHP, almost any code written can be seen as an expression, usually a combination of variables, constants and operators, and so on!

PHP Basic Knowledge Point Summary (i)

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.