Problems related to bool and =

Source: Internet
Author: User
The official php Manual provides an example of bool and = operations: Beware & nbsp; of & nbsp; certain & nbsp; control & nbsp; behavior & nbsp; with & nbsp; boolean & nbsp; and & nbsp; non & nb bool and =
An example is provided in the official php manual:

Beware of certain control behavior with boolean and non boolean values :

// Consider that the 0 could by any parameters including itself
var_dump(0 == 1); // false
var_dump(0 == (bool)'all'); // false
var_dump(0 == 'all'); // TRUE, take care
var_dump(0 === 'all'); // false

// To avoid this behavior, you need to cast your parameter as string like that :
var_dump((string)0 == 'all'); // false
?> 


Why var_dump (0 = 'all'); is true. Does the = operator cause type conversion?
But why ......
------ Solution --------------------
Yes, php converts the data type.
Since it is relatively large, it must be the same data type for comparison.

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.