|
| 1 | +Numeric string comparison |
| 2 | +========================= |
| 3 | + |
| 4 | +TODO: description |
| 5 | + |
| 6 | +Example: |
| 7 | +-------- |
| 8 | +(http://3v4l.org/6OPhQ) |
| 9 | + |
| 10 | +```php |
| 11 | +echo "Compare non numeric string to string 0: ('str' == '0') = " . ('str' == '0' ? 'true' : 'false') . "\n"; |
| 12 | +echo "Compare non numeric string to integer 0: ('str' == 0) = " . ('str' == 0 ? 'true' : 'false') . "\n"; |
| 13 | + |
| 14 | +echo "Compare evtl. numeric string to string: ('1string' == '1') = " . ('1string' == '1' ? 'true' : 'false') . "\n"; |
| 15 | +echo "Compare evtl. numeric string to number: ('1string' == 1) = " . ('1string' == 1 ? 'true' : 'false') . "\n"; |
| 16 | + |
| 17 | +echo "Compare two numeric strings (same semantic 1): ('1e1' == '10') = " . ('1e1' == '10' ? 'true' : 'false') . "\n"; |
| 18 | +echo "Compare two numeric strings (same semantic 2): ('1E1' == '10') = " . ('1E1' == '10' ? 'true' : 'false') . "\n"; |
| 19 | +echo "Compare two numeric strings (same semantic 3): ('1e-1' == '0.1') = " . ('1e-1' == '0.1' ? 'true' : 'false') . "\n"; |
| 20 | +echo "Compare two numeric strings (same semantic 4): ('1E-1' == '0.1') = " . ('1E-1' == '0.1' ? 'true' : 'false') . "\n"; |
| 21 | +echo "Compare two numeric strings (same semantic 5): ('+1' == '1') = " . ('+1' == '1' ? 'true' : 'false') . "\n"; |
| 22 | +echo "Compare two numeric strings (same semantic 6): ('+0' == '-0') = " . ('+0' == '-0' ? 'true' : 'false') . "\n"; |
| 23 | + |
| 24 | +echo "Compare two numeric strings (precision 1): ('0.99999999999999994' == '1') = " . ('0.99999999999999994' == '1' ? 'true' : 'false') . "\n"; |
| 25 | +echo "Compare two numeric strings (precision 2): ('0.99999999999999995' == '1') = " . ('0.99999999999999995' == '1' ? 'true' : 'false') . "\n"; |
| 26 | +``` |
| 27 | + |
| 28 | +``` |
| 29 | +Compare non numeric string to string 0: ('str' == '0') = false |
| 30 | +Compare non numeric string to integer 0: ('str' == 0) = true |
| 31 | +Compare evtl. numeric string to string: ('1string' == '1') = false |
| 32 | +Compare evtl. numeric string to number: ('1string' == 1) = true |
| 33 | +Compare two numeric strings (same semantic 1): ('1e1' == '10') = true |
| 34 | +Compare two numeric strings (same semantic 2): ('1E1' == '10') = true |
| 35 | +Compare two numeric strings (same semantic 3): ('1e-1' == '0.1') = true |
| 36 | +Compare two numeric strings (same semantic 4): ('1E-1' == '0.1') = true |
| 37 | +Compare two numeric strings (same semantic 5): ('+1' == '1') = true |
| 38 | +Compare two numeric strings (same semantic 6): ('+0' == '-0') = true |
| 39 | +Compare two numeric strings (precision 1): ('0.99999999999999994' == '1') = false |
| 40 | +Compare two numeric strings (precision 2): ('0.99999999999999995' == '1') = true |
| 41 | +``` |
0 commit comments