PHP Basics (First day)
PHP tags
1, to know that PHP is a kind of embedded HTML document scripting language; PHP syntax format is: <?php want to write content? The red body is the PHP tag, note that these tags are entered in the English input method.
2, PHP tags have four kinds: standard tag, script tag, short label, ASP tag.
Standard label
<?php
echo ' Hello word '; This is the simplest output Hello Word, note that the end of the code is terminated with the English semicolon.
A semicolon represents a line of code that you want to express, and we are mostly using standard tags to write code.
?>
Script tags
Syntax format:
<script language= ' PHP ' >
PHP code--This kind of writing we hardly need
</script>
Short Label:
<?
PHP code
Now the default is to turn off Short_tag = On in php.ini must be turned on
PHP.ini is a php extension file that configures PHP various functions
It's safe to say that people who write with this code are almost extinct.
?>
ASP tags
ASP Tags: In order to let ASP program ape to PHP excessive
<%
PHP code
Not supported by default, Asp_tag = On must be turned on
Same as the short label.
%>
Comments
Note: Mainly for people to see, the computer will automatically ignore, a good programmer to write something not only you can see the understanding and let others see, for example, a line of code to show that the explanation is what the comment;
There are two types of annotations: single-line comments and multiline comments
This is a single-line comment, only one line
For example: $a = $b + $c//This is an algorithm that assigns the value of the left $b+ $c to $ A
#这也是单行注释
Multiline comment: A piece of content, a multiline comment, everything from the start symbol to the ending symbol, regardless of what kind of content will be back commented out.
/*
The content of the comment
*/
PHP Basic Syntax
All code inside the PHP tag (except for annotations) must follow the PHP scripting rules
PHP code is in the unit of behavior, each line must have a statement terminator: semicolon ";"
PHP Code Writing Specification: Structure indentation
The last line of code in the PHP code can have no statement terminator semicolon: in PHP understanding, if you encounter the PHP end tag, the system also believes that the previous line of statements end (the end tag contains a statement terminator semicolon: not recommended)
Echo is followed by the content to be output, the content can be output multiple times, using the comma "," to separate the data
Amount
Volume: There are long and short, divided into two constants, variables, to see their nature depends on how they store their memory
Constant: Fixed.
Variable: variable at any time.
Some syntax rules for variables
1, is to start with the $ symbol for example, $ABC and A, $ABC is the variable ABC is not a variable
2.
3. Variable name: can only be letters, numbers and underscores, and cannot start with a number
4. Declaring variables in PHP is the definition of variables
Using variables
Define variables: When the data is stored in memory, there is no way to find it directly, it is necessary to store the data in the location (memory address), and find the data is the memory address stored by the variable to find the data.
changing variables
For example: $a = 100;
$a = 200;
At this time $a=200;
Delete a variable
The essence of deleting a variable is to free up memory
For example: $a = 100; You can delete data so $a=null so that $ A is an empty shell, and null means nothing.
If you want to remove $ A also can be used unset (variable name); Empty the memory address stored by the variable, and release the variable itself at the same time
Constant
There are two ways of defining constants
Using const and define ()
Syntax: const PI=100 define (PI,100) as long as echo pi; results two are all, pi refers to the constant name
Modify Constants & Delete Constants
Constants cannot be modified or deleted
Some basic differences between a variable and a constant
1 definitions are defined in different ways, constants are defined by const or define (), and variables are used with the $ symbol
2 constants can not change values, and variables can be changed at any time
3 Constants cannot be deleted (note: When the execution of a script automatically deletes a constant instead of a true deletion), the variable can be deleted at any time.
4 variables are case-sensitive, constants are not necessarily
Variable case-sensitive
Const-defined constants are also case-sensitive
Define function default case-sensitive
However, the Define function can be case-insensitive: The third parameter of the Define function needs to be used: true
System constants
Constant defined inside the system
Maximum value that can be represented by an integer in the php_int_max:php
The following constants start with a double underline and end with a double underline: this is called the magic constant
MAGIC constant: The constant is assigned to the system in the position corresponding to the constant
__file__: Gets the absolute path (with file name) of the current script
__DIR__: Gets the absolute path of the current script (without the file name)
The following constants start with a double underline and end with a double underline: this is called the magic constant
MAGIC constant: The constant is assigned to the system in the position corresponding to the constant
__file__: Gets the absolute path (with file name) of the current script
__DIR__: Gets the absolute path of the current script (without the file name)
__LINE__: Gets the current line number
__FUNCTION__: Can only be used inside the function, get the name of the function
__METHOD__: Can only be used inside a method, get the name of the method (with Class)
Variable passing
Two types: reference passing and value passing
Value passing
Value passing: Copies the data of the memory address stored by the variable directly, passing the newly copied content to another variable: two values for two variables in the system
Most of the data in PHP is passed by default, with special (objects and resources)
Reference delivery
Memory address of the data store stored by the variable
Reference passing: The memory address of a variable is saved to another variable: two variables in the system, one value
$ variable 1 = &$ variable 2;
Variable variable
mutable variable: The value of one variable is exactly the name of another variable, and you can directly access the value of another variable by accessing the current variable more than one level.
PHP Basics (Share some previous notes every day hoping to help self-taught friends)