Those years of learning PHP together (2)

Source: Internet
Author: User

Now we start our PHP coding journey in the Linux world. There will be various problems in coding, and the time to solve the problem is also the time for us to change from new to New.
Every programming language starts from the variable. PHP is a type of embedded scripting language and can also start from the Data Type of the syntax. This section describes the data types and variables of PHP.
Data Types in PHP:
(1) Boolean value, [true, false] Q: there are only two definitions of Boolean values: true and false. PHP defines variables to be represented by $, for example, $ shop = false;
(2) The INTEGER (decimal, octal, and hexadecimal) supported integers are related to the platform. for PHP5 and earlier versions, the integer can be given to the power of 31 of 2, PHP6 introduces 63 power integer data. in decimal format, the hexadecimal format is basically a mathematical conversion.
(3) floating point data, including single precision floating point [float], double Precision Floating Point [double], and real number [real number]. It can contain decimal point values to indicate currency and distance, for example, defining a number $ money = 1.0093 is a floating point value by default.
(4) single quotation mark string, that is, enclose the text to be used with single quotation marks. For example, 'I am Siron .'
Q: How can I write This's book is highly enjoyable?
Fields in double quotation marks are interpreted by the compiler and output in HTML code.
The single quotation mark field is directly output without being interpreted by the compiler.
For example: Copy codeThe Code is as follows: <? Php
$ Bookname = "Lua programming guide Chinese version ";
// Double quotation marks ----- output Lua programming guide Chinese Version
Echo "$ bookname ";
// Single quotes ---- output $ bookname
Echo '$ bookname ';
// For example, note that the single quotation mark must be escaped \'
Echo "My book \'s name is $ bookname ";

(5) double quotation mark string, that is, enclose the text to be used with double quotation marks, but it is more complicated. Double quotation marks can be replaced with variables. For example, "I am Siron ."
(6) array type. An array can exist as a key-Value Pair and supports multi-dimensional arrays. Brief definition exampleCopy codeThe Code is as follows: <? Php
// Define an array containing three elements
$ Books [0] = "C # guide ";
$ Books [1] = "besieged city ";
$ Books [2] = "Hangzhou ";

(7) The object type belongs to the Data Type and will be described in detail later in object-oriented programming.
Blengder = new Application;
(8) resource Type
$ File = fopen ("1.txt", r) // This is a resource type.
(9) is PHP a weak language? Can I force type conversion?
For PHP forced type conversion (converting one data type to another), add the forced conversion data type before the variable. however, during the conversion process, the data of the variable is lost when the high-precision floating point number is converted to a low-precision value. Therefore, be cautious when using the variable. the forced conversion types include (bool) (array) (int) (integer) (object) (real) (double) (float) (string ). PHP type definition is very loose, so sometimes the system automatically converts to the appropriate type according to the environment where the referenced variable is located.Copy codeThe Code is as follows: <? Php
$ Total = 5; // integer
$ Count = "25"; // string
$ Total + = "$ count"; // $ total = 30 (automatically converted to an integer)

(10) What built-in functions are used related to types?
PHP uses the built-in gettype () function to return the variable Type specified by Var, and uses settype () to convert var to the specified Type. That is, gettype () 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, and unknown type. Syntax: string gettype (mixed var );
Settype () This function is used to configure or convert the variable type. True is returned. Otherwise, false is returned. The var parameter is the original variable name. The type parameter is of one of the following types: integer, double, string, array, and object. Syntax: int settype (string var, string type );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.