php notes: Analysis of data type and constant usage

  • 2020-06-03 05:56:39
  • OfStack

setType - Sets the type of the variable

bool settype ( mixed $var , string $type )
Set the type of the variable var to type.

The possible values of type are:

The & # 8226; "boolean" (or "bool", starting from PHP 4.2.0)
The & # 8226; "integer" (or "int", starting from PHP 4.2.0)
The & # 8226; "float" (available only after PHP 4.2.0, deactivated for "double" used in older versions)
The & # 8226; "string"
The & # 8226; "array"
The & # 8226; "object"
The & # 8226; "null" (from PHP 4.2.0 onwards)

Returns TRUE on success and FALSE on failure.

intval(), floatval(), stringval() do not change the type of the original variable.

isset - Checks if the variable is set

bool isset ( mixed $var [, mixed $var [, $... ]] )

Returns TRUE if var exists, FALSE if not.

If a variable has been released using unset(), it will no longer be isset(). Testing a variable set to NULL using isset() returns FALSE. Also note that 1 NULL byte ("\0") is not equal to the NULL constant of PHP.

Note: Warning isset() can only be used for variables because passing any other parameter causes a parsing error. To detect if a constant is set, use the defined() function.

empty - Checks if 1 variable is null

bool empty ( mixed $var )
If var is a non-null or non-zero value, empty() returns FALSE. In other words, "", 0, 0, NULL, FALSE, array(), var $var; If var is null, TRUE is returned, with no warning when the variable is not set.

unset - Releases the given variable

void unset ( mixed $var [, mixed $var [, $... ]] )
unset() destroys the specified variable. Note that in PHP 3, unset() returns TRUE (which is actually an integer value of 1), while in PHP 4, unset() is no longer a real function: it is now a statement. There is no return value, and trying to get the return value of unset() results in a parsing error.

gettype - Gets the type of the variable

string gettype ( mixed $var )
Returns the type of the PHP variable var.

Variable type test function


Refer to the manual for notes

1. Regular functions
bool copy ( string source, string dest )
2. With mixed, mixed means any type of data can be passed
bool chown ( string filename, mixed user )
With 3. & A function of a parameter, which is a reference assignment, can't pass a value, can only pass a variable, and then the function changes the value of the variable, and when we use the variable, the value changes
bool arsort ( array & array [, int sort_flags] )

4. The default function is a function with [], which means that this parameter is optional. If you pass the value, use the value you pass, and if you pass no value, use the default value
When a function is declared, an initial value is given for the argument.
Optional and required values must be set from back to front
bool arsort ( array & array [, int sort_flags] )

5. With... Parameter function of... Means that any number of parameters can be passed
int array_unshift ( array & array, mixed var [, mixed ...] )

6. Call back function with callback, which means to call this function, we need to pass in 1 function (function name, function name string)
array array_filter ( array input [, callback callback] )

Related articles: