Skip to content

Commit a1ac1b0

Browse files
author
Tomáš Votruba
authored
Merge pull request piotrplenik#139 from peter-gribanov/comparison
Comparison section
2 parents 03ecd69 + c537087 commit a1ac1b0

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

README.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -390,34 +390,38 @@ function createMicrobrewery(string $breweryName = 'Hipster Brew Co.'): void
390390

391391
## Comparison
392392

393-
**[⬆ back to top](#table-of-contents)**
394-
395393
### Use [identical comparison](http://php.net/manual/en/language.operators.comparison.php)
396394

397395
**Not good:**
398396

397+
The simple comparison will convert the string in an integer.
398+
399399
```php
400400
$a = '42';
401401
$b = 42;
402-
// Use the simple comparison that will convert the string in an int
403402

404-
if( $a != $b ) {
403+
if ($a != $b) {
405404
// The expression will always pass
406405
}
407-
408406
```
409-
The comparison $a != $b returns false but in fact it's true!
410-
The string '42' is different than the int 42.
407+
408+
The comparison `$a != $b` returns `FALSE` but in fact it's `TRUE`!
409+
The string `42` is different than the integer `42`.
411410

412411
**Good:**
413-
Use the identical comparison will compare type and value
412+
413+
The identical comparison will compare type and value.
414+
414415
```php
415-
if( $a !== $b ) {
416-
//The expression is verified
417-
}
416+
$a = '42';
417+
$b = 42;
418418

419+
if ($a !== $b) {
420+
// The expression is verified
421+
}
419422
```
420-
The comparison $a !== $b returns true.
423+
424+
The comparison `$a !== $b` returns `TRUE`.
421425

422426
**[⬆ back to top](#table-of-contents)**
423427

0 commit comments

Comments
 (0)