


Learn comparison operations and logical operations in PHP through examples
string When converting number, intercept the numeric string on the left for conversion, if not then returns 0,
Arrays can directly perform string concatenation operations but cannot perform mathematical operations. It is always true to convert the object type to boolean. The object type cannot be converted to number and string, so string concatenation and mathematical operations cannot be performed. The way to convert a scalar to an array is to set the first element of the array to a scalar and return the array. The scalar is converted to object to get an instance of the stdClass class, and the scalar value is assigned to the property named scalar: Object( [scalar] => 234) Convert array to object to get an instance of stdClass class. The key of the array is the attribute name of the class. Converting object to array is a bit complicated: Methods, static properties, and class constants are discarded Protected attribute names are preceded by a "*" Private properties are preceded by the class name (the case is exactly the same as the class name) For example, an array converted from object is: Array( [*v] => 444 [bf] => 333 [bk] => 99977 [Ak] => 999 [*p] => 888 [a2] => 22) The original objects include: public attribute a2, protected attributes v, p, which class these attributes come from cannot be identified (if overridden, the attributes of the subclass will be taken) Private attributes f and k from class b (from the perspective of the array key, taking bf as an example, it is impossible to determine whether the attribute name is bf or the private attribute f from class b) private property k from class A It is impossible to identify which of b and A is the subclass and which is the parent class (just from the key of the array, it is also impossible to infer which class the original object was constructed from) 5. Logical operations always return true or false (people who write a lot of JavaScript should pay attention). The priority of logical operators from high to low is &&, ||, and, or. The short-circuit effect of logical operators can be used in statements. , but remember that they will not return a value that is not a boolean type like in JavaScript, so be careful when using it in expressions.
6. The comparison of switch is not "===" but "==" (in javascript it is "===") 7. In php4, the comparison method between objects is the same as that of array. In php5, the "==" comparison between object types is true only if they belong to instances of the same class (of course, attributes must also be compared Comparison, this is similar to the "===" comparison of scalars), the "===" comparison between objects is true only if they are the same object. In PHP4, objects that do not include any member variables are judged to be true by empty() String offset offset takes the character's empty() judgment: Take the character corresponding to offset for judgment. Before PHP5.4, when using the index to get characters from the string, the index will be rounded first, so the left side does not contain Numeric strings are converted to 0. After PHP5.4, string indexes in non-integer formats are no longer rounded, so it is judged to be true. Similarly, isset() is judged to be false. For example:
Whether it is "not equal to" or "==", do not use "transitiveness" in cross-type data comparison in PHP: $a == $b; //true $b == $c; //true It does not mean that $a == $c is true Array comparison method
8. Ternary operator?:, unlike most other programming languages, PHP's ternary operator is left associative!
The ternary operation expression is divided into ( $arg == 'B' ) ? 'bus' : ( $arg == 'A' ) ? 'airplane' : ( $arg == 'T' ) ? 'train' : ( $arg == 'C' ) ? 'car' : ( $arg == 'H' ) ? 'horse' : 'feet' ; |

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...
