Copy CodeThe code is as follows:
/* Data types convert to and from each other
* One is a cast
* SETTYPE (variable, type); Int,integer,float,double and so on.
* This function changes the type of the original variable, using Var_dump (); You can view the variable
*
* Used in the form of (type) before assignment, does not change the type of the original variable
* $a = (int) "123ABC";
*
* $ variable =intval (variable or value);
* $ variable =floatval (variable or value);
* $ variable =stringval (variable or value);
*
* Note: integer type is 4 bytes in memory 2.147e9
* Floating-point type 8 bytes in memory
*
*
* One is automatic conversion (the most common way), the variable will be more run environment automatic conversion
* Some common functions related to variables and types
* Isset ();//Determine if a variable exists, and the value if NULL also indicates null.
* Empty ();//Determine if a variable is null "", NULL
* unset ();//Delete a variable
* SetType ();//Set a variable type
* GetType ();//Get a variable type var_dump (); Get type and value
*
* Variable type test function
* Is_bool ();//Whether the Boolean type is determined
* Is_int () Is_integer () Is_long ()//Determine if the integer type
* Is_float (), is_double () is_real ()//...
* Is_array ()
* Is_object ()
* Is_resource ()
* Is_null ()
* Is_scalar ()//Determine if it is a scalar
* Is_numberic ()//judge whether it is any kind of number, or numeric string
* Is_callable ()//Determine if the function name is valid
* Declaration and use of constants
* 1. Constant is an identifier for a simple value
* 2. The constant definition cannot change its value, nor can it use unset () or any other function to cancel
* 3. Constants can be defined and accessed anywhere by ignoring the rules of variable scope
* 4. Constants use define ("Constant name", value);
* 5. The constant name does not use "$" when declaring and using
* 6. Constant names are used in uppercase
* 7. The value of a constant can only be in scalar type (int,float,bool,string)
* 8. Constants must be given values at the time of declaration
* 9.defined ("constant");//Determine if the constant exists
*
* Predefined Constants and Magic constants
* Echo __file__;//output Current file name Directory _ Magic constant
* echo case_lower;//Output Fixed value _ pre-defined constant
*
*/
This function changes the type of the original variable, using Var_dump (); You can view the variable
$str = "100.12345ABC";
SetType ($str, int);
Var_dump ($STR);
Used in the form of (type) before assignment
$str = "100.12345ABC";
$a = (int) $str;
Var_dump ($a);//output int (100)
Var_dump ($STR);//output value unchanged, "100.12345ABC"
If the string does not start with a number, it is converted to 0
Different types of operations
$a = 10;
$b = "100ABC";
$c =true;
$d = 12.34;
$sum = $a + $c;//Boolean auto-Convert to 1, result 11
$sum = $a + $b;//result is 110
$sum = $a + $b + $c;//result is 111
$sum = $a + $b + $c + $d;//The result is 123.34 because the floating-point memory space is large and small memory is turned into large memory.
Determines whether an array is
$a =array ("one", "one", "1,3,6,8");
if (Is_array ($a)) {
Print_r ($a);//print array
}else{
echo $a;
}
Defining constants, using constants
Define ("Home", "This is a Home");
$a = 100;
Function Demo ()
{
Global $a;//Because $ A is a global variable, it is called with the GLOBALS tag
echo $a;
Echo home;//constants can be ignored, accessed directly or defined
}
Demo ();
Determine if a constant exists
if (Defined ("Home")
{
Echo home;
}
Else
{
Define ("Home", "This is a Home");
}
The above describes the Photoshop Learning tutorial PHP Learning data types between the conversion code, including the Photoshop Learning tutorial content, I hope to be interested in PHP tutorial friends helpful.