cvs: /phpdoc/language operators.sgml

From: Date: Mon, 15 Nov 1999 23:11:27 +0000
Subject: cvs: /phpdoc/language operators.sgml
Groups: php.dev 
Request: Send a blank email to php-dev+get-12574@lists.php.net to get a copy of this message
cslawi Mon Nov 15 18:11:27 1999 EDT Modified files: /phpdoc/language operators.sgml Log: Alphabetization fix. Added === to the precedence table. Added pre- and post- increment and decrement operators. Various small fixes. Index: phpdoc/language/operators.sgml diff -u phpdoc/language/operators.sgml:1.6 phpdoc/language/operators.sgml:1.7 --- phpdoc/language/operators.sgml:1.6 Mon Nov 15 05:34:08 1999 +++ phpdoc/language/operators.sgml Mon Nov 15 18:11:27 1999 @@ -29,7 +29,7 @@ <row> <entry>$a - $b</entry> <entry>Subtraction</entry> - <entry>Remainder of $b subtracted from $a.</entry> + <entry>Difference of $a and $b.</entry> </row> <row> <entry>$a * $b</entry> @@ -157,8 +157,8 @@ <sect1 id="language.operators.comparison"> <title>Comparison Operators</title> <simpara> - Comparison operators, as their name imply, allow you to compare two - values. + Comparison operators, as their name implies, allow you to compare + two values. </simpara> <table> @@ -212,13 +212,20 @@ </tgroup> </table> - <para> - Another conditional operator is the "?:" (or trinary) operator, which - operates as in C and many other languages. - <informalexample><programlisting>(expr1) ? (expr2) : (expr3);</programlisting></informalexample> - This expression returns to <replaceable>expr2</replaceable> if - <replaceable>expr1</replaceable> evalutes to true, and expr3 if - <replaceable>expr1</replaceable> evaluates to false. + <para> + Another conditional operator is the "?:" (or trinary) operator, + which operates as in C and many other languages. + + <informalexample> + <programlisting> +(expr1) ? (expr2) : (expr3); + </programlisting> + </informalexample> + + This expression evaluates to <replaceable>expr2</replaceable> if + <replaceable>expr1</replaceable> evaluates to true, and + <replaceable>expr3</replaceable> if + <replaceable>expr1</replaceable> evaluates to false. </para> </sect1> @@ -250,8 +257,84 @@ </para> </sect1> + + + <sect1 id="language.operators.increment"> + <title>Incrementing/Decrementing Operators</title> - <sect1 id="language.operators.logical"> + <para> + PHP supports C-style pre- and post-increment and decrement + operators. + </para> + + <table> + <title>Increment/decrement Operators</title> + <tgroup cols="3"> + <thead> + <row> + <entry>example</entry> + <entry>name</entry> + <entry>effect</entry> + </row> + </thead> + <tbody> + <row> + <entry>++$a</entry> + <entry>Pre-increment</entry> + <entry>Increments $a by one, then returns $a.</entry> + </row> + <row> + <entry>$a++</entry> + <entry>Post-increment</entry> + <entry>Returns $a, then increments $a by one.</entry> + </row> + <row> + <entry>--$a</entry> + <entry>Pre-decrement</entry> + <entry>Decrements $a by one, then returns $a.</entry> + </row> + <row> + <entry>$a--</entry> + <entry>Post-decrement</entry> + <entry>Returns $a, then decrements $a by one.</entry> + </row> + </tbody> + </tgroup> + </table> + + <para> + Here's a simple example script: + <informalexample> + <programlisting> +&lt;?php +echo "&lt;h3&gt;Postincrement&lt;/h3&gt;"; +$a = 5; +echo "Should be 5: " . $a++ . "&lt;br&gt;\n"; +echo "Should be 6: " . $a . "&lt;br&gt;\n"; + +echo "&lt;h3&gt;Preincrement&lt;/h3&gt;"; +$a = 5; +echo "Should be 6: " . ++$a . "&lt;br&gt;\n"; +echo "Should be 6: " . $a . "&lt;br&gt;\n"; + +echo "&lt;h3&gt;Postdecrement&lt;/h3&gt;"; +$a = 5; +echo "Should be 5: " . $a-- . "&lt;br&gt;\n"; +echo "Should be 4: " . $a . "&lt;br&gt;\n"; + +echo "&lt;h3&gt;Predecrement&lt;/h3&gt;"; +$a = 5; +echo "Should be 4: " . --$a . "&lt;br&gt;\n"; +echo "Should be 4: " . $a . "&lt;br&gt;\n"; +?&gt; + </programlisting> + </informalexample> + </para> + + </sect1> + + + <sect1 id="language.operators.logical"> <title>Logical Operators</title> <table> @@ -299,10 +382,13 @@ </tgroup> </table> - <simpara> - The reason for the two different variations of "and" and "or" - operators is that they operate at different precedences. (See below.) - </simpara></sect1> + <simpara> + The reason for the two different variations of "and" and "or" + operators is that they operate at different precedences. (See + <link linkend="language.operators.precedence">Operator + Precedence</link>.) + </simpara> + </sect1> <sect1 id="language.operators.precedence"> <title>Operator Precedence</title> @@ -376,7 +462,7 @@ </row> <row> <entry>non-associative</entry> - <entry>== !=</entry> + <entry>== != ===</entry> </row> <row> <entry>non-associative</entry>

« previous php.dev (#12574) next »