PHP simple learning variables and constants

Write catalog title here

variable

The PHP language is a weakly typed language and can be used directly without the need to declare variable types.
The function var_dump (variable name) can be used to output the variable type

bool type
bool type includes true and false, namely true and false
wang'bian'liang'li'cun
specific use is not yet clear
int integer
storage integer
float floating point
storage decimal
string string
storage string
use single quotation marks, Double quotes, delimiters, three ways to define.
Single quotation marks
, as shown, the single quotation marks can be placed on any character
Insert picture description here
but which can not be placed in single quotes, being given
Insert picture description here
if required in single quotes to make characters stored value is available \ in front flag
Insert picture description here
double quotes
substantially single quotes no big difference
, but double quotes Substitute the variables contained in the output, single quotes will not work
Insert picture description here

Insert picture description here

Delimiter The
delimiter
must start with <<< this symbol, and then define the name, enter the character variable with a space and then end with the defined name.
Various characters can be added in the middle
Insert picture description here

In the delimiter, the variable contained in it can also be substituted for output

Insert picture description here
Array (array) and object (object) reource (resource)
will be recorded in the blog after learning.
NULL
means that the variable is not assigned or the variable is assigned to NULL, or the variable
that is destroyed by the unset function. In short, it is the variable type that has not been assigned.
Coercion and mutual conversion of variable types

Insert picture description here
Suggest not to dig yourself

constant

Definition of constants The
Insert picture description here
first single quotation mark is the constant name, and the second single quotation mark is the constant value.
Insert picture description here
Its characteristics are

  1. Can only be defined with define()
  2. Generally speaking, the names of constants are uppercase
  3. Can be defined and used anywhere, regardless of the rules of variables
  4. Once defined, it cannot be undefined and redefined
  5. The value of a constant can only be bool, int, float, string type
    predefined constants,
    PHP has helped us define the constants,
    commonly used

Show how many lines the current code is in __LINE_

echo LINE ;
Get the absolute path of the current file FILE

echo FILE ;
Get the directory where the current file is located __DIR_

echo DIR ;
Get the name of the current method __FUNCTION__

function test() { echo FUNCTION ; } test(); //The result is: //test gets the name of the current namespace, which is the name of the namespace __NAMESPACE__





namespace xxxx\index;
echo NAMESPACE ;
//The result is:
// xxxx\index
gets the name of the current class __CLASS__

class test {
    function l() {
        echo __CLASS__;
    }
}
(new test)->l();
// 结果为:
//   test

Get the name of the current method.
When it exists alone, the return value of __FUNCTION__ is the same;
however, when it is in the same class as __FUNCTION__, __METHOD__ will be preceded by a class name. For example, the class name:: Method name

class Test { public function must () { echo FUNCTION ; } public function mustAgain () { echo METHOD ; } } $ obj = new Test (); $ obj-> must (); echo ' '; $ obj-> mustAgain (); // 结果 为 :// must // Test :: mustAgain














Guess you like

Origin blog.csdn.net/qq_51954912/article/details/114002279