-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathif.xml
91 lines (89 loc) · 2.68 KB
/
if.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- $Author$ -->
<!-- EN-Revision: 7104ee97ced1768a3231588dfc0bc0d7eb1117ad Maintainer: dallas Status: ready -->
<sect1 xml:id="control-structures.if" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>if</title>
<?phpdoc print-version-for="if"?>
<para>
<literal>if</literal> 结构是很多语言包括 PHP
在内最重要的特性之一,它允许按照条件执行代码片段。PHP 的
<literal>if</literal> 结构和 C 语言相似:
<informalexample>
<programlisting>
<![CDATA[
<?php
if (expr)
statement
?>
]]>
</programlisting>
</informalexample>
</para>
<simpara>
如同在<link
linkend="language.expressions">表达式</link>一章中定义的,<replaceable>expr</replaceable>
按照布尔求值。如果 <replaceable>expr</replaceable>
的值为 &true;,PHP 将执行 <replaceable>statement</replaceable>,如果值为
&false; ——将忽略 <replaceable>statement</replaceable>。有关哪些值被视为
&false; 的更多信息参见<link
linkend="language.types.boolean.casting">转换为布尔值</link>一节。
</simpara>
<para>
如果 <varname>$a</varname> 大于 <varname>$b</varname>,则以下例子将显示
<computeroutput>a is bigger than b</computeroutput>:
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
if ($a > $b)
echo "a is bigger than b";
?>
]]>
</programlisting>
</informalexample>
</para>
<para>
经常需要按照条件执行不止一条语句,当然并不需要给每条语句都加上一个
<literal>if</literal> 子句。可以将这些语句放入语句组中。例如,如果
<varname>$a</varname> 大于 <varname>$b</varname>,以下代码将显示
<computeroutput>a is bigger than b</computeroutput> 并且将
<varname>$a</varname> 的值赋给 <varname>$b</varname>:
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
if ($a > $b) {
echo "a is bigger than b";
$b = $a;
}
?>
]]>
</programlisting>
</informalexample>
</para>
<simpara>
<literal>if</literal> 语句可以无限层地嵌套在其它
<literal>if</literal> 语句中,这给程序的不同部分的条件执行提供了充分的弹性。
</simpara>
</sect1>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->