|
18 | 18 | </thead> |
19 | 19 | <tbody> |
20 | 20 | <row> |
21 | | - <entry>+$a</entry> |
| 21 | + <entry><code>+$a</code></entry> |
22 | 22 | <entry>Identity</entry> |
23 | 23 | <entry> |
24 | 24 | Conversion of <varname>$a</varname> to <type>int</type> or |
25 | 25 | <type>float</type> as appropriate. |
26 | 26 | </entry> |
27 | 27 | </row> |
28 | 28 | <row> |
29 | | - <entry>-$a</entry> |
| 29 | + <entry><code>-$a</code></entry> |
30 | 30 | <entry>Negation</entry> |
31 | 31 | <entry>Opposite of <varname>$a</varname>.</entry> |
32 | 32 | </row> |
33 | 33 | <row> |
34 | | - <entry>$a + $b</entry> |
| 34 | + <entry><code>$a + $b</code></entry> |
35 | 35 | <entry>Addition</entry> |
36 | 36 | <entry>Sum of <varname>$a</varname> and <varname>$b</varname>.</entry> |
37 | 37 | </row> |
38 | 38 | <row> |
39 | | - <entry>$a - $b</entry> |
| 39 | + <entry><code>$a - $b</code></entry> |
40 | 40 | <entry>Subtraction</entry> |
41 | 41 | <entry>Difference of <varname>$a</varname> and <varname>$b</varname>.</entry> |
42 | 42 | </row> |
43 | 43 | <row> |
44 | | - <entry>$a * $b</entry> |
| 44 | + <entry><code>$a * $b</code></entry> |
45 | 45 | <entry>Multiplication</entry> |
46 | 46 | <entry>Product of <varname>$a</varname> and <varname>$b</varname>.</entry> |
47 | 47 | </row> |
48 | 48 | <row> |
49 | | - <entry>$a / $b</entry> |
| 49 | + <entry><code>$a / $b</code></entry> |
50 | 50 | <entry>Division</entry> |
51 | 51 | <entry>Quotient of <varname>$a</varname> and <varname>$b</varname>.</entry> |
52 | 52 | </row> |
53 | 53 | <row> |
54 | | - <entry>$a % $b</entry> |
| 54 | + <entry><code>$a % $b</code></entry> |
55 | 55 | <entry>Modulo</entry> |
56 | 56 | <entry>Remainder of <varname>$a</varname> divided by <varname>$b</varname>.</entry> |
57 | 57 | </row> |
58 | 58 | <row> |
59 | | - <entry>$a ** $b</entry> |
| 59 | + <entry><code>$a ** $b</code></entry> |
60 | 60 | <entry>Exponentiation</entry> |
61 | 61 | <entry>Result of raising <varname>$a</varname> to the <varname>$b</varname>'th power.</entry> |
62 | 62 | </row> |
63 | 63 | </tbody> |
64 | 64 | </tgroup> |
65 | 65 | </table> |
66 | 66 | <simpara> |
67 | | - The division operator ("/") returns a float value unless the two operands |
68 | | - are integers (or strings that get converted to integers) and the numbers |
69 | | - are evenly divisible, in which case an integer value will be returned. For |
70 | | - integer division, see <function>intdiv</function>. |
| 67 | + The division operator <literal>/</literal> returns a <type>float</type> |
| 68 | + value unless the two operands are <type>int</type> (or |
| 69 | + <link linkend="language.types.numeric-strings">numeric strings</link> |
| 70 | + which are type juggled to <type>int</type>) and the numerator is a multiple |
| 71 | + of the divisor, in which case an integer value will be returned. |
| 72 | + For integer division, see <function>intdiv</function>. |
71 | 73 | </simpara> |
72 | 74 | <simpara> |
73 | 75 | Operands of modulo are converted to <type>int</type> |
|
76 | 78 | </simpara> |
77 | 79 | <para> |
78 | 80 | The result of the modulo operator <literal>%</literal> has the same sign |
79 | | - as the dividend — that is, the result of <literal>$a % $b</literal> |
| 81 | + as the dividend — that is, the result of <code>$a % $b</code> |
80 | 82 | will have the same sign as <varname>$a</varname>. For example: |
81 | 83 | <informalexample> |
82 | 84 | <programlisting role="php"> |
83 | 85 | <![CDATA[ |
84 | 86 | <?php |
85 | 87 |
|
86 | | -echo (5 % 3)."\n"; // prints 2 |
87 | | -echo (5 % -3)."\n"; // prints 2 |
88 | | -echo (-5 % 3)."\n"; // prints -2 |
89 | | -echo (-5 % -3)."\n"; // prints -2 |
| 88 | +var_dump(5 % 3); |
| 89 | +var_dump(5 % -3); |
| 90 | +var_dump(-5 % 3); |
| 91 | +var_dump(-5 % -3); |
90 | 92 |
|
91 | 93 | ?> |
92 | 94 | ]]> |
93 | 95 | </programlisting> |
| 96 | + &example.outputs; |
| 97 | + <screen> |
| 98 | +<![CDATA[ |
| 99 | +int(2) |
| 100 | +int(2) |
| 101 | +int(-2) |
| 102 | +int(-2) |
| 103 | +]]> |
| 104 | + </screen> |
94 | 105 | </informalexample> |
95 | 106 | </para> |
96 | 107 | <sect2 role="seealso"> |
|
0 commit comments