PHP type conversion, constants, system constants, magic constants, constants

Source: Internet
Author: User
Tags constant definition

PHP type conversion, constants, system constants, magic constants, constants

PHP type conversion, constants, system constants, and magic Constants

1. Automatic type conversion;

During operation and judgment, automatic type conversion is performed; 1) convert other types to bool; 1) convert to boolean type conversion; 1) convert integer to boolean type conversion from 0 to false; convert non-0 to true; 2) convert null strings and '0' ("0") to false, convert others to true; 3) convert empty arrays to false, and convert non-empty arrays to true; 4) convert null to false 5) if the resource is not successfully opened, the value is 0 or null. If the resource is not opened successfully, convert the value to 'false' or '0'. 2) convert other types to strings (String concatenation ); null bool int float 1) convert null to null String (empty string not displayed) 2) convert integer directly to corresponding string 5 => '5'; 3) convert real number directly to corresponding string, but the end 0 is not converted (the last 0 decimal point of the real number); 4) true is converted to '1', false is converted to an empty string; string, Boolean, integer, floating point, null3) type conversion during operation 1) true/false to 1/0; 2) null to 0; 3) values starting with a string are converted to the corresponding values; 4) if the string starts with no value, it is directly converted to 0; (null, string, bool) <int <float

2. Forced type conversion

Is to manually convert a type value to another type value; 1. type conversion functions intval, strval, floatval $ num1 = 1.2; $ num2 = strval ($ num1 ); // convert the value of $ num1 to a string; var_dump ($ num1); var_dump ($ num2); 2. (type) $ variable cannot be converted to resource $ num2 = (unset) $ num2; convert to null 3. The settype (variable, type) type must be written as a string; change the type and value of the variable; Note 1) convert the floating point to an integer to directly remove decimal places; 2) echo (int) ($ num1 + 0.5); rounding

3. Constants

1) constant definition define (constant name, constant value) define ('song', 22); Note: 1) constant name is a string; 2) constant value must be a scalar 3) the constant name is generally in uppercase and different from the variable. 4) the constant name and variable name have the same naming rules. 2) system constant _ LINE _ current row number _ FILE _ current FILE name _ DIR _ current FILE directory; PHP_ OS operating system PHP_VERSION php version magic constant: __function _ FUNCTION name__ FUNCTION _ FUNCTION name; __class _ CLASS name _ METHOD _ NAMESPACE __: NAMESPACE _ NAMESPACE; 3) constant judgment defined (constant name) constant name must be a string; judge whether a constant has been defined;

4. Operators and expressions;

1) Arithmetic Operator +-(multiplication)/(Division) %. % modulo/remainder 0% 3 = 012% 10 = 25% 19 = 41% 3 = 1; 2% 3 = 2; 3% 3 = 0; -9% 4 =-19%-4 = 1; the result symbol of the modulo operation depends on the first number. Judge that the parity X % 2 = 0 is an even number, which can be divisible by X % 2! If it is set to 0, it is an odd number and cannot be divided into 2*3 = 8 exponent operations; 2 3 = 8; 3 2 = 9;

If you have any questions, please leave a message or go to the community on this site for discussion. Thank you for reading this article. Thank you for your support!

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: info-contact@alibabacloud.com 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.