mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
Comparison of numerical strings (bug #23110)
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@165552 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
c101f55cbd
commit
c0a982bd43
1 changed files with 27 additions and 1 deletions
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.77 $ -->
|
||||
<!-- $Revision: 1.78 $ -->
|
||||
<chapter id="language.operators">
|
||||
<title>Operators</title>
|
||||
<simpara>
|
||||
|
@ -461,6 +461,32 @@ echo "hallo" ^ "hello"; // Outputs the ascii values #0 #4 #0 #0 #0
|
|||
</tbody>
|
||||
</tgroup>
|
||||
</table>
|
||||
<para>
|
||||
If you compare integer with the string, the string is
|
||||
<link linkend="language.types.string.conversion">converted to number</link>.
|
||||
If you compare two numerical strings, they are compared as integers. These
|
||||
rules are valid also for the
|
||||
<link linkend="control-structures.switch">switch</link> statement.
|
||||
<informalexample>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
var_dump(0 == "a"); // 0 == 0 -> true
|
||||
var_dump("1" == "01"); // 1 == 1 -> true
|
||||
|
||||
switch ("a") {
|
||||
case 0:
|
||||
echo "0";
|
||||
break;
|
||||
case "a": // never reached because "a" is already matched with 0
|
||||
echo "a";
|
||||
break;
|
||||
}
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</informalexample>
|
||||
</para>
|
||||
<para>
|
||||
Another conditional operator is the "?:" (or ternary) operator.
|
||||
<informalexample>
|
||||
|
|
Loading…
Reference in a new issue