|
|
Line 7: |
Line 7: |
| $myZeroString = ''; | | $myZeroString = ''; |
| | | |
| + | var_dump($myVar); |
| | | |
− | === type casting ===
| + | http://php.net/manual/en/types.comparisons.php |
− | | |
− | Да се внимава със загубата на информация
| |
− | | |
− |
| |
− | | |
− | $myVar = 1.1;
| |
− | $myVar = (int) $myVar;
| |
− | $myVar = (string) $myVar;
| |
− | $myVar = (bool) $myVar;
| |
− | | |
− | var_dump($myVar);
| |
| | | |
| //var_dump( $myZero = $myVar ); | | //var_dump( $myZero = $myVar ); |
Line 41: |
Line 31: |
| //var_dump( $myString === $myZero ); | | //var_dump( $myString === $myZero ); |
| | | |
| + | Да се внимава със загубата на информация |
| | | |
− | <table class="doctable table">
| + | $myVar = 1.1; |
− | <caption><strong>Comparisons of <var class="varname"><var class="varname">$x</var></var> with PHP functions</strong></caption>
| + | $myVar = (int) $myVar; |
− |
| + | $myVar = (string) $myVar; |
− | <thead>
| + | $myVar = (bool) $myVar; |
− | <tr>
| |
− | <th>Expression</th>
| |
− | <th> <span class="function"><a href="function.gettype.php" class="function">gettype()</a></span></th>
| |
− | <th> <span class="function"><a href="function.empty.php" class="function">empty()</a></span></th>
| |
− | <th> <span class="function"><a href="function.is-null.php" class="function">is_null()</a></span></th>
| |
− | <th> <span class="function"><a href="function.isset.php" class="function">isset()</a></span></th>
| |
− | <th><span class="type"><a href="language.types.boolean.php" class="type boolean">boolean</a></span> : <em>if($x)</em></th>
| |
− | </tr>
| |
− | | |
− | </thead>
| |
− | | |
− | <tbody class="tbody">
| |
− | <tr>
| |
− | <td><em>$x = "";</em></td>
| |
− | <td><span class="type"><a href="language.types.string.php" class="type string">string</a></span></td>
| |
− | <td><strong><code>TRUE</code></strong></td>
| |
− | <td><strong><code>FALSE</code></strong></td>
| |
− | <td><strong><code>TRUE</code></strong></td>
| |
− | <td><strong><code>FALSE</code></strong></td>
| |
− | </tr>
| |
− | | |
− | <tr>
| |
− | <td><em>$x = null;</em></td>
| |
− | <td><span class="type"><a href="language.types.null.php" class="type NULL">NULL</a></span></td>
| |
− | <td><strong><code>TRUE</code></strong></td>
| |
− | <td><strong><code>TRUE</code></strong></td>
| |
− | <td><strong><code>FALSE</code></strong></td>
| |
− | <td><strong><code>FALSE</code></strong></td>
| |
− | </tr>
| |
− | | |
− | <tr>
| |
− | <td><em>var $x;</em></td>
| |
− | <td><span class="type"><a href="language.types.null.php" class="type NULL">NULL</a></span></td>
| |
− | <td><strong><code>TRUE</code></strong></td>
| |
− | <td><strong><code>TRUE</code></strong></td>
| |
− | <td><strong><code>FALSE</code></strong></td>
| |
− | <td><strong><code>FALSE</code></strong></td>
| |
− | </tr>
| |
− | | |
− | <tr>
| |
− | <td><var class="varname"><var class="varname">$x</var></var> is undefined</td>
| |
− | <td><span class="type"><a href="language.types.null.php" class="type NULL">NULL</a></span></td>
| |
− | <td><strong><code>TRUE</code></strong></td>
| |
− | <td><strong><code>TRUE</code></strong></td>
| |
− | <td><strong><code>FALSE</code></strong></td>
| |
− | <td><strong><code>FALSE</code></strong></td>
| |
− | </tr>
| |
− | | |
− | <tr>
| |
− | <td><em>$x = array();</em></td>
| |
− | <td><span class="type"><a href="language.types.array.php" class="type array">array</a></span></td>
| |
− | <td><strong><code>TRUE</code></strong></td>
| |
− | <td><strong><code>FALSE</code></strong></td>
| |
− | <td><strong><code>TRUE</code></strong></td>
| |
− | <td><strong><code>FALSE</code></strong></td>
| |
− | </tr>
| |
− | | |
− | <tr>
| |
− | <td><em>$x = false;</em></td>
| |
− | <td><span class="type"><a href="language.types.boolean.php" class="type boolean">boolean</a></span></td>
| |
− | <td><strong><code>TRUE</code></strong></td>
| |
− | <td><strong><code>FALSE</code></strong></td>
| |
− | <td><strong><code>TRUE</code></strong></td>
| |
− | <td><strong><code>FALSE</code></strong></td>
| |
− | </tr>
| |
− | | |
− | <tr>
| |
− | <td><em>$x = true;</em></td>
| |
− | <td><span class="type"><a href="language.types.boolean.php" class="type boolean">boolean</a></span></td>
| |
− | <td><strong><code>FALSE</code></strong></td>
| |
− | <td><strong><code>FALSE</code></strong></td>
| |
− | <td><strong><code>TRUE</code></strong></td>
| |
− | <td><strong><code>TRUE</code></strong></td>
| |
− | </tr>
| |
− | | |
− | <tr>
| |
− | <td><em>$x = 1;</em></td>
| |
− | <td><span class="type"><a href="language.types.integer.php" class="type integer">integer</a></span></td>
| |
− | <td><strong><code>FALSE</code></strong></td>
| |
− | <td><strong><code>FALSE</code></strong></td>
| |
− | <td><strong><code>TRUE</code></strong></td>
| |
− | <td><strong><code>TRUE</code></strong></td>
| |
− | </tr>
| |
− | | |
− | <tr>
| |
− | <td><em>$x = 42;</em></td>
| |
− | <td><span class="type"><a href="language.types.integer.php" class="type integer">integer</a></span></td>
| |
− | <td><strong><code>FALSE</code></strong></td>
| |
− | <td><strong><code>FALSE</code></strong></td>
| |
− | <td><strong><code>TRUE</code></strong></td>
| |
− | <td><strong><code>TRUE</code></strong></td>
| |
− | </tr>
| |
− | | |
− | <tr>
| |
− | <td><em>$x = 0;</em></td>
| |
− | <td><span class="type"><a href="language.types.integer.php" class="type integer">integer</a></span></td>
| |
− | <td><strong><code>TRUE</code></strong></td>
| |
− | <td><strong><code>FALSE</code></strong></td>
| |
− | <td><strong><code>TRUE</code></strong></td>
| |
− | <td><strong><code>FALSE</code></strong></td>
| |
− | </tr>
| |
− | | |
− | <tr>
| |
− | <td><em>$x = -1;</em></td>
| |
− | <td><span class="type"><a href="language.types.integer.php" class="type integer">integer</a></span></td>
| |
− | <td><strong><code>FALSE</code></strong></td>
| |
− | <td><strong><code>FALSE</code></strong></td>
| |
− | <td><strong><code>TRUE</code></strong></td>
| |
− | <td><strong><code>TRUE</code></strong></td>
| |
− | </tr>
| |
− | | |
− | <tr>
| |
− | <td><em>$x = "1";</em></td>
| |
− | <td><span class="type"><a href="language.types.string.php" class="type string">string</a></span></td>
| |
− | <td><strong><code>FALSE</code></strong></td>
| |
− | <td><strong><code>FALSE</code></strong></td>
| |
− | <td><strong><code>TRUE</code></strong></td>
| |
− | <td><strong><code>TRUE</code></strong></td>
| |
− | </tr>
| |
− | | |
− | <tr>
| |
− | <td><em>$x = "0";</em></td>
| |
− | <td><span class="type"><a href="language.types.string.php" class="type string">string</a></span></td>
| |
− | <td><strong><code>TRUE</code></strong></td>
| |
− | <td><strong><code>FALSE</code></strong></td>
| |
− | <td><strong><code>TRUE</code></strong></td>
| |
− | <td><strong><code>FALSE</code></strong></td>
| |
− | </tr>
| |
− | | |
− | <tr>
| |
− | <td><em>$x = "-1";</em></td>
| |
− | <td><span class="type"><a href="language.types.string.php" class="type string">string</a></span></td>
| |
− | <td><strong><code>FALSE</code></strong></td>
| |
− | <td><strong><code>FALSE</code></strong></td>
| |
− | <td><strong><code>TRUE</code></strong></td>
| |
− | <td><strong><code>TRUE</code></strong></td>
| |
− | </tr>
| |
| | | |
− | <tr>
| |
− | <td><em>$x = "php";</em></td>
| |
− | <td><span class="type"><a href="language.types.string.php" class="type string">string</a></span></td>
| |
− | <td><strong><code>FALSE</code></strong></td>
| |
− | <td><strong><code>FALSE</code></strong></td>
| |
− | <td><strong><code>TRUE</code></strong></td>
| |
− | <td><strong><code>TRUE</code></strong></td>
| |
− | </tr>
| |
| | | |
− | <tr>
| |
− | <td><em>$x = "true";</em></td>
| |
− | <td><span class="type"><a href="language.types.string.php" class="type string">string</a></span></td>
| |
− | <td><strong><code>FALSE</code></strong></td>
| |
− | <td><strong><code>FALSE</code></strong></td>
| |
− | <td><strong><code>TRUE</code></strong></td>
| |
− | <td><strong><code>TRUE</code></strong></td>
| |
− | </tr>
| |
| | | |
− | <tr>
| |
− | <td><em>$x = "false";</em></td>
| |
− | <td><span class="type"><a href="language.types.string.php" class="type string">string</a></span></td>
| |
− | <td><strong><code>FALSE</code></strong></td>
| |
− | <td><strong><code>FALSE</code></strong></td>
| |
− | <td><strong><code>TRUE</code></strong></td>
| |
− | <td><strong><code>TRUE</code></strong></td>
| |
− | </tr>
| |
| | | |
− | </tbody>
| |
− |
| |
− | </table>
| |
| | | |
| | | |