constant

Common scenario

<? PHP // Define constant form 1 define("PI1", 3.14); // Define constant form 2 const PI2 = 3.1416; $s1 = PI1 * 2 * 2; // // calculate the area of a circle with radius 3, using PI2 as PI $s2 = PI2 * 3 * 3; $s3 = constant("PI1") * 4 * 4; $s3 = constant("PI1") * 4; Echo "<br> $s1; Echo "<br> $s2; Echo "<br> $s3; // If the constant PI1 is not defined, if(! Defined ("PI1")) {// Then define it here! Define (" PI1, 3.14); $s1 = PI1 * 2 * 2; $s1 = PI1 * 2; // Just use the constant here. >Copy the code

Predefined constant

<? PHP echo "<br> ", PHP_INT_MAX; Echo "<br> PI = ", M_PI; Echo "<h1> </h1> Echo "<br> ", __DIR__; Echo "<br> ", __FILE__; Echo "<br> Line number of current line: ", __LINE__; Echo "<br> Line number of current line: ", __LINE__; ? >Copy the code

Type judgment

Gettype () : Gets the type of a variable, resulting in the name of a variable type(string)

$v1 = 10; $r1 = gettype( $v1 ); // Result: "integer" $v2 = 'ABC '; $r2 = gettype( $v2 ); // Result: "string"Copy the code

Settype () : Sets the type of a variable

$v1 = 10; Settype ($v1, 'string'); $v1 = "10"; $v1 = "10";Copy the code

Var_dump () : Outputs “complete information” about variables

var_dump($s) //string(3) "123"
Copy the code

Determine whether it is a certain type

Is_int ()/is_INTEGER () : checks whether it is an integer is_float() : checks whether it is a floating point is_bool() : checks whether it is a Boolean is_String () :... Is_array () :... Is_numeric () : determines whether it is of the "numeric" type (including integers, decimals, and "pure numeric strings") is_Object () : two special judgments: isset() : Returns true if there is data in a variable, and false empty() if there is none. Return true if it is indeed "empty", false otherwise. The meaning of "empty" is closer to the meaning of "nothing" in everyday life. There is no such thing as a blank space in a computer.Copy the code