Simple syntax for getting started with PHP
1. The "echo" command is to tell the server to print a string of characters.
2. Explanation: The "var_dump" function can display the data type of our variables (described later in the section).
3. We can get the memory consumed by the current PHP by using "Memory_get_usage".
4. In PHP, 8 primitive types are supported, including four scalar types, two composite types, and two special types. PHP is a loosely-typed language that does not have to declare the variable's data type to PHP, and PHP automatically converts the variable into an automatic data type, which reduces the threshold of learning PHP to a certain extent.
$string = "Just be";
Var_dump ($string);
echo "
";
$string = 9494;
Var_dump ($string);
echo "
";
?>
It is important to note that when we use the "echo" command to Output a Boolean type, if "true" then the output is "1", "false" will not output anything.
5. Scientific notation can use lowercase e, or uppercase E.
6. The string type can be defined in three ways: single-quote , double-quote , and heredoc-structured .
When a variable is enclosed in double quotes, the variable is concatenated with the contents of the double quotation mark;
When a variable is included in a single quotation mark, the variable is exported as a string.
7. We can solve this problem by using the heredoc structure form , first using the delimiter to represent the string (<<<), then providing an identifier after "<<<" GOD, then the string , ending the string with the supplied identifier.
8. Resources (Resource): resources are created and used by specialized functions, such as open files, data connections, and graphical canvases. We can manipulate resources (create, use, and release). Any resources should be released in a timely manner when they are not needed. If we forget to release the resources, the system automatically enables the garbage collection mechanism to reclaim the resources after the page has been executed to avoid the memory being exhausted.
First, the "fopen" function is used to open the file, and the return value is the resource type.
$file _handle=fopen ("/data/webroot/resource/php/f.txt", "R");
if ($file _handle) {
It then uses a while loop (described in detail in the loop structure in the following language structure statement) to read the file line by row, and then output the text for each line
while (!feof ($file _handle)) {//Determines whether to the last row
$line = fgets ($file _handle); Reading a line of text
Echo $line; Output a line of text
echo "
"; Line break
}
}
Fclose ($file _handle);//Close file
?>
9.NULL (NULL): null is a null type, is not case sensitive, the null type has only one value, indicating that a variable has no value, when it is assigned null, or has not been assigned, or is unset (), the variables are considered NULL in three cases.
Constants in 10.PHP are divided into custom constants and system constants.
11. The first parameter "Constant_name" is a required parameter, a constant name, that is, a marker, the name of the constant is consistent with the variable, but note oh, it does not have the dollar sign OH. The second parameter, "value," is a required parameter, which is the value of the constant. The third parameter, "Case_sensitive", is an optional parameter, specifying whether it is case sensitive, set to true to be insensitive, and generally without specifying a third parameter, the value of the default third parameter is False.
12. The main function of constants is to avoid duplicate definitions and tamper with variable values. When we are working on team development, or when the code is very large, for some quantities that do not change after the first definition, if we use variables, without knowing the same variable name, the value of the variable will be replaced, which will cause the server to perform the wrong task.
In addition, the use of constants can also improve the maintainability of the code. If for some reason the value of the constant needs to be changed, we only need to modify one place.
13. System constants are constants that PHP has already defined, and we can use them directly, and common system constants are:
(1) __file__:p hp program file name. It can help us get the current file in the physical location of the server.
(2) __line__:P HP program file line number. It can tell us the current code in the first few lines.
(3) Php_version: The version number of the current parser. It can tell us the current PHP parser version number, we can know in advance whether our PHP code can be parsed by the PHP parser.
(4) Php_os: Executes the current PHP version of the operating system name. It can tell us the name of the operating system used by the server, and we can optimize our code based on the operating system.
14. There are two ways to take a value for a constant value. The first is to get the value directly using the constant name;
The second is the use of the constant () function. It is the same as the direct use of the output of the constant name, but the function can be dynamically output different constants, in the use of flexible, convenient, the syntax format is as follows:
Mixed constant (string constant_name)
The defined () function helps us to determine whether a constant has been defined and its syntax is:
bool Defined (string constants_name)
There are two types of assignment operators for 15.PHP, namely:
(1) "=": assigns the value of the right expression to the left operand. It copies the value of the right expression to the left-hand operand. In other words, the left operand is first requested for a piece of memory, and then the copied value is placed in this memory.
(2) "&": Reference assignment means that both variables point to the same data. It will allow two variables to share a piece of memory, and if the memory stored data changes, then the values of the two variables will change.
$a = "I am learning php! in mu-class net ";
$b = $a;
$c =& $a;
$a = "I am learning php! every day in Mu-class net ";
echo $b. "
";
echo $c. "
";
?>
("?:") The ternary operator is also a comparison operator, for expressions (EXPR1)? (EXPR2):(EXPR3), if the value of EXPR1 is true, the value of this expression is expr2, otherwise EXPR3.
$a = TRUE; A agree
$b = TRUE; B Agree
$c = FALSE; C Objection
$d = FALSE; D against
Let's review the ternary operator.
Echo ($a and $b)? " Pass ":" does not pass ";
echo "
";
Echo ($a or $c)? " Pass ":" does not pass ";
echo "
";
Echo ($a xor $c xor $d)? " Pass ":" does not pass ";
echo "
";
Echo (! $c? "Pass": "does not pass");
echo "
";
echo $a && $d? " Pass ":" does not pass ";
echo "
";
echo $b | | $c | | $d? " Pass ":" does not pass ";
?>
16. The string join operator is to concatenate two strings, and the string join operators provided in PHP are:
(1) Join operator (".") : It returns the string that is appended to the right argument after the left argument.
(2) Connection assignment operator (". ="): It attaches the right argument to the left argument.
An error control operator "@" is provided in 17.PHP, and we do not want to display an error message to the customer when there are errors in the operation, which is unfriendly to the user. Therefore, you can put the @ before a PHP expression, any error message that the expression may produce is ignored;
If the Track_error (which is set in php.ini) is activated, any error message generated by the expression is stored in the variable $php_errormsg, which is overwritten every time an error occurs, so you must check it as early as possible if you want to use it.
It is important to note that the error control prefix "@" does not mask the parsing of the error information, it cannot be placed before the definition of a function or class, nor can it be used for conditional structures such as if and foreach.
18. In PHP, the Foreach Loop statement, commonly used to iterate over an array, is generally used in two ways: Do not remove the label, remove the label.
(1) value only, do not remove the label
(2) Remove the mark and value at the same time
Value) {//Perform the task}?>
$students = Array (
' I ' = ' make Fox rush ',
' + ' and ' 林平 ',
' I ' and ' Song Yang ',
' ~ ' = ' ren ying ',
' The ' and ' to ask the heavens ',
' + ' = ' let me Do ',
' ~ ' and ' dashed ',
' = ' and ' founder ',
' 2018 ' and ' Yue Qun ',
' 2019 ' and ' Ning Zhong ',
)///10 student's number and name, stored in an array
Iterate through an array using the loop structure to get the number and name
foreach ($students as $v)
{
echo $v;//output (print) name
echo "
";
}
?>
$students = Array (
' =>array ' (' Linghutao ', ' 59 '),
' =>array ' (' 林平 ', "44"),
' =>array ' (' Qu Yang ', ' 89 '),
' =>array ' (' Ren Ying ', ' 92 '),
' =>array ' (' to ask the Heavens ', "93"),
' =>array ' (' Any line ', ' 87 '),
' =>array ' (' dashed ', ' 58 '),
' =>array ' (' founder ', ' 74 '),
' 2018 ' =>array (' Yue Qun ', ' 91 '),
' 2019 ' =>array (' Ning Zhong ', "90"),
)////10 student's number, name, score, stored in an array
foreach ($students as $key = $val)
{//Use loop structure to iterate through the array, get the study number
Echo $key; Output number
echo ":";
Loop output name and score
foreach ($val as $v)
{
Echo $v;
}
echo "
";
}
?>
2016-04-01 15:38:03