Home  >  Article  >  Backend Development  >  Introduction to PHP (basic, variables, constants, structural statements)

Introduction to PHP (basic, variables, constants, structural statements)

WBOY
WBOYOriginal
2016-07-25 08:46:22785browse

Getting started with PHP (basic, variables, constants, structural statements), friends in need can refer to it.


Basic common sense:
?>Can be omitted The string concatenation character is . Comment // Variable
The first letter of the variable must be $, starting with a letter or underscore "_"
It can only be composed of letters, numbers, and "_", and can also contain Chinese characters
case sensitive The "var_dump" function can display the data type of our variables and has line breaks. When we use the "echo" command to output a Boolean type, if it is "true", the output is "1", and if "false", nothing is output. When a variable is enclosed in double quotes, the variable will be concatenated with the content in the double quotes;
When a variable is enclosed in single quotes, the variable will be output as a string. Long string: delimiter definedefinition System constants
(1) __FILE__: PHP program file name. It can help us get the physical location of the current file on the server.
(2)__LINE__: The number of lines in the PHP program file. It can tell us which line the current code is on.
(3) PHP_VERSION: The version number of the current parser. It can tell us the version number of the current PHP parser, and we can know in advance whether our PHP code can be parsed by the PHP parser.
(4) PHP_OS: The name of the operating system that executes the current PHP version. It can tell us the name of the operating system used by the server and we can optimize our code according to that operating system Constant value
Use constant name directly mixed constant(string constant_name);//returns a variety of information, and returns an error message if it fails bool defined(string constants_name); determine whether the variable is defined variable reference & String concatenation operator
. .=//Connection with assignment Structural statement
(1) Only take the value, do not remove the subscript

foreach (array as value){
//Tasks to be executed
}
?>

(2) Remove the subscript and value at the same time

foreach (array as subscript => value){
//Tasks to be executed
}
?>
php


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn