Now we enter the Linux world and start our PHP coding journey. Various problems will occur in coding, and the time to solve the problem is also the time for us to transform from a novice.
Each programming language starts with variable practice. PHP is an embedded scripting language, and of course it can also start with syntax data types. This section mainly starts with PHP data types and data variables.
Data types for PHP language:
(1) Boolean value, [true,false] Question: There are only two definitions of Boolean value: true, false, PHP definition variables agree to be expressed by $, such as $shop=false;
(2) Integer [Decimal, Octal, Hexadecimal] The supported integers are related to the platform. For PHP5 and previous versions support +2 to the power of 31, PHP6 introduces integer data to the power of 63. Decimal, hexadecimal is basically converted according to mathematics.
(3) Floating-point data, including single-fine floating point [float], double-fine floating point [double], and real number [real number], can contain the value of the decimal part, used to represent currency, distance, and other representations that simple integers cannot satisfy. For example, define a number $money=1.0093. By default, it is a floating-point value.
(4) Single quote string, that is, use single quotes to enclose the text you want to use. For example: 'I am Siron.'
Q: If I were to write This's book is highly enjoyable. How should I write it?
Notes on using single and double quotes in PHP:
The double quoted fields are interpreted by the compiler and then output through HTML code.
Single quote fields will not be interpreted by the compiler and will be output directly.
Give an example:
<?php
$bookname="Lua Programming Guide Chinese Version";
//Double Quotes ----Output Lua Programming Guide Chinese Version
echo “$bookname";
//Single quotes----Output $bookname
echo '$bookname';
//For example, cross-output, please note that single quotes should be escaped \'
echo “ My book\'s name is $bookname";
?>
(5) Double quote string, that is, use double quotes to enclose the text you want to use, but it is more complicated. Variable replacement can be used in double quotes. For example: "I am Siron."
(6) Array type, arrays can exist in key-value pairs and support multi-dimensional arrays. A brief definition example
<?php
//Define a single array, containing three elements in total
$books[0]="C# Guide";
$books[1]="Siege";
$books[2]="Japanese version";
?>
(7) Object type is a data type that is in line with the data type, which will be introduced in detail later in object-oriented programming.
$
blengder =new Application;
(8) Resource type
$file=fopen("",r)//This is the resource type
(9) Is PHP a weak-type language? Can type conversion be casted?
Regarding PHP casting (that is, converting one data type to another type), you can add a cast data type before the variable. However, it should be noted that during the conversion process, the data of the variable is lost when high-precision floating-point numbers are converted to low-precision values, so be careful to use. The types of casting include (bool)(array)(int)(integer)(object)(real)(double)(float)(string). The PHP type definition is very loose, so it is sometimes automatically converted to the appropriate type based on the environment in which the reference variable is located.
<?php
$total=5; //Integer
$count="25";//String
$total+="$count";//$total=30 (automatically convert to integer)
?>
(10) What are the built-in functions that are used for type?
PHP uses the gettype() function to return the variable type specified by Var, and uses settype() to convert var to the type specified by Type. That is: gettype() This function is used to obtain the type of the variable. The returned type string may be one of the following strings: integer, double, string, array, object, unknown type. Syntax: string gettype(mixed var);
settype() This function is used to configure or convert variable types. Returns true value successfully, and false value in other cases. The parameter var is the original variable name, and the parameter type is one of the following types: integer, double, string, array and object. Syntax: int settype(string var, string type);
Each programming language starts with variable practice. PHP is an embedded scripting language, and of course it can also start with syntax data types. This section mainly starts with PHP data types and data variables.
Data types for PHP language:
(1) Boolean value, [true,false] Question: There are only two definitions of Boolean value: true, false, PHP definition variables agree to be expressed by $, such as $shop=false;
(2) Integer [Decimal, Octal, Hexadecimal] The supported integers are related to the platform. For PHP5 and previous versions support +2 to the power of 31, PHP6 introduces integer data to the power of 63. Decimal, hexadecimal is basically converted according to mathematics.
(3) Floating-point data, including single-fine floating point [float], double-fine floating point [double], and real number [real number], can contain the value of the decimal part, used to represent currency, distance, and other representations that simple integers cannot satisfy. For example, define a number $money=1.0093. By default, it is a floating-point value.
(4) Single quote string, that is, use single quotes to enclose the text you want to use. For example: 'I am Siron.'
Q: If I were to write This's book is highly enjoyable. How should I write it?
Notes on using single and double quotes in PHP:
The double quoted fields are interpreted by the compiler and then output through HTML code.
Single quote fields will not be interpreted by the compiler and will be output directly.
Give an example:
Copy the codeThe code is as follows:
<?php
$bookname="Lua Programming Guide Chinese Version";
//Double Quotes ----Output Lua Programming Guide Chinese Version
echo “$bookname";
//Single quotes----Output $bookname
echo '$bookname';
//For example, cross-output, please note that single quotes should be escaped \'
echo “ My book\'s name is $bookname";
?>
(5) Double quote string, that is, use double quotes to enclose the text you want to use, but it is more complicated. Variable replacement can be used in double quotes. For example: "I am Siron."
(6) Array type, arrays can exist in key-value pairs and support multi-dimensional arrays. A brief definition example
Copy the codeThe code is as follows:
<?php
//Define a single array, containing three elements in total
$books[0]="C# Guide";
$books[1]="Siege";
$books[2]="Japanese version";
?>
(7) Object type is a data type that is in line with the data type, which will be introduced in detail later in object-oriented programming.
$
blengder =new Application;
(8) Resource type
$file=fopen("",r)//This is the resource type
(9) Is PHP a weak-type language? Can type conversion be casted?
Regarding PHP casting (that is, converting one data type to another type), you can add a cast data type before the variable. However, it should be noted that during the conversion process, the data of the variable is lost when high-precision floating-point numbers are converted to low-precision values, so be careful to use. The types of casting include (bool)(array)(int)(integer)(object)(real)(double)(float)(string). The PHP type definition is very loose, so it is sometimes automatically converted to the appropriate type based on the environment in which the reference variable is located.
Copy the codeThe code is as follows:
<?php
$total=5; //Integer
$count="25";//String
$total+="$count";//$total=30 (automatically convert to integer)
?>
(10) What are the built-in functions that are used for type?
PHP uses the gettype() function to return the variable type specified by Var, and uses settype() to convert var to the type specified by Type. That is: gettype() This function is used to obtain the type of the variable. The returned type string may be one of the following strings: integer, double, string, array, object, unknown type. Syntax: string gettype(mixed var);
settype() This function is used to configure or convert variable types. Returns true value successfully, and false value in other cases. The parameter var is the original variable name, and the parameter type is one of the following types: integer, double, string, array and object. Syntax: int settype(string var, string type);