cvs: phpdoc /kr/language control-structures.xml expressions.xml
| From: | WonHee Hwang | Date: | Wed, 10 Jan 2001 10:54:00 +0000 |
| Subject: | cvs: phpdoc /kr/language control-structures.xml expressions.xml | ||
| Groups: | php.doc | ||
| Request: | Send a blank email to phpdoc+get-969333532@lists.php.net to get a copy of this message | ||
regina Wed Jan 10 02:54:00 2001 EDT
Modified files:
/phpdoc/kr/language control-structures.xml expressions.xml
Log:
Index: phpdoc/kr/language/control-structures.xml diff -u phpdoc/kr/language/control-structures.xml:1.2 phpdoc/kr/language/control-structures.xml:1.3 --- phpdoc/kr/language/control-structures.xml:1.2 Tue Jan 9 16:41:17 2001 +++ phpdoc/kr/language/control-structures.xml Wed Jan 10 02:54:00 2001 @@ -1,49 +1,48 @@ - <chapter id="control-structures"> - <title>Control Structures</title> - - <simpara> - Any PHP script is built out of a series of statements. A statement - can be an assignment, a function call, a loop, a conditional - statement of even a statement that does nothing (an empty - statement). Statements usually end with a semicolon. In addition, - statements can be grouped into a statement-group by encapsulating a - group of statements with curly braces. A statement-group is a - statement by itself as well. The various statement types are - described in this chapter. +<chapter id="control-structures"> + <title>ì ì´ êµ¬ì¡° (Control Structures)</title> + <simpara> + 모ë PHP ì¤í¬ë¦½í¸ë ì¼ë ¨ì 구문ì¼ë¡ ì´ë£¨ì´ ì§ë¤. + íëì 구문ì ëì ë¬¸ì´ ë ìë ìê³ , í¨ì í¸ì¶, ë°ë³µë¬¸, ì¡°ê±´ë¬¸ì´ ë ìë ìì¼ë©° + ì¬ì§ì´ë ì무 ë´ì©ì´ ìë ë¹ ë¬¸ì¥ì¼ ìë ìë¤. + í 구문ì ì¼ë°ì ì¼ë¡ ì¸ë¯¸ì½ë¡ (;)ì¼ë¡ ëëë¤. + ëí ì¬ë¬ê°ì 구문ì ì¤ê´í¸({,})를 ì¬ì©íì¬ íëì 그룹ì¼ë¡ ë§ë¤ì´ ì¬ì©í ìë ìë¤. + ì´ êµ¬ë¬¸-그룹ì ê·¸ 그룹ì 모ë 구문ë¤ì´ íëì êµ¬ë¬¸ì¸ ê²ì²ë¼ ì¸ìëë¤. + ì¬ê¸°ìë ì¬ë¬ ê°ì§ 구문ííì ëí´ ìì본ë¤. </simpara> - - <sect1 id="control-structures.if"> - <title><literal>if</literal></title> - <para> + <sect1 id="control-structures.if"> + <title> + <literal>if</literal> + </title> + <para> The <literal>if</literal> construct is one of the most important features of many languages, PHP included. It allows for - conditional execution of code fragments. PHP features an - <literal>if</literal> structure that is similar to that of C: + conditional execution of code fragments. + PHPì <literal>if</literal> 문ì Cì ë¹ì·íë¤.: <informalexample> - <programlisting> + <programlisting> if (expr) statement </programlisting> - </informalexample> - </para> - <simpara> + </informalexample> + </para> + <simpara> As described in the section about expressions, expr is evaluated to its truth value. If <replaceable>expr</replaceable> evaluates to <literal>TRUE</literal>, PHP will execute statement, and if it evaluates to <literal>FALSE</literal> - it'll ignore it. </simpara> - <para> + <para> The following example would display <computeroutput>a is bigger than b</computeroutput> if <replaceable>$a</replaceable> is bigger than <replaceable>$b</replaceable>: <informalexample> - <programlisting role="php"> + <programlisting role="php"> if ($a > $b) print "a is bigger than b"; </programlisting> - </informalexample> - </para> - <para> + </informalexample> + </para> + <para> Often you'd want to have more than one statement to be executed conditionally. Of course, there's no need to wrap each statement with an <literal>if</literal> clause. Instead, you can group @@ -53,25 +52,26 @@ <replaceable>$b</replaceable>, and would then assign the value of <replaceable>$a</replaceable> into <replaceable>$b</replaceable>: <informalexample> - <programlisting role="php"> + <programlisting role="php"> if ($a > $b) { print "a is bigger than b"; $b = $a; } </programlisting> - </informalexample> - </para> - <simpara> + </informalexample> + </para> + <simpara> If statements can be nested indefinitely within other <literal>if</literal> statements, which provides you with complete flexibility for conditional execution of the various parts of your program. </simpara> - </sect1> - - <sect1 id="control-structures.else"> - <title><literal>else</literal></title> - <para> + </sect1> + <sect1 id="control-structures.else"> + <title> + <literal>else</literal> + </title> + <para> Often you'd want to execute a statement if a certain condition is met, and a different statement if the condition is not met. This is what <literal>else</literal> is for. <literal>else</literal> @@ -83,29 +83,29 @@ <replaceable>$b</replaceable>, and <computeroutput>a is NOT bigger than b</computeroutput> otherwise: <informalexample> - <programlisting role="php"> + <programlisting role="php"> if ($a > $b) { print "a is bigger than b"; } else { print "a is NOT bigger than b"; } </programlisting> - </informalexample> + </informalexample> The <literal>else</literal> statement is only executed if the <literal>if</literal> expression evaluated to <literal>FALSE</literal>, and if there were any <literal>elseif</literal> expressions - only if they evaluated to - <literal>FALSE</literal> as well (see <link - linkend="control-structures.elseif">elseif</link>). + <literal>FALSE</literal> as well (see <link linkend="control-structures.elseif">elseif</link>). </para> - </sect1> - - <sect1 id="control-structures.elseif"> - <title><literal>elseif</literal></title> - <para> - <literal>elseif</literal>, as its name suggests, is a combination + </sect1> + <sect1 id="control-structures.elseif"> + <title> + <literal>elseif</literal> + </title> + <para> + <literal>elseif</literal>, as its name suggests, is a combination of <literal>if</literal> and <literal>else</literal>. Like <literal>else</literal>, it extends an <literal>if</literal> statement to execute a different statement in case the original @@ -118,7 +118,7 @@ b</computeroutput>, <computeroutput>a equal to b</computeroutput> or <computeroutput>a is smaller than b</computeroutput>: <informalexample> - <programlisting role="php"> + <programlisting role="php"> if ($a > $b) { print "a is bigger than b"; } elseif ($a == $b) { @@ -127,9 +127,9 @@ print "a is smaller than b"; } </programlisting> - </informalexample> - </para> - <simpara> + </informalexample> + </para> + <simpara> There may be several <literal>elseif</literal>s within the same <literal>if</literal> statement. The first <literal>elseif</literal> expression (if any) that evaluates to @@ -140,7 +140,7 @@ behavior) but the bottom line is that both would result in exactly the same behavior. </simpara> - <simpara> + <simpara> The <literal>elseif</literal> statement is only executed if the preceding <literal>if</literal> expression and any preceding <literal>elseif</literal> expressions evaluated to @@ -148,40 +148,32 @@ <literal>elseif</literal> expression evaluated to <literal>TRUE</literal>. </simpara> - </sect1> - - <sect1 id="control-structures.alternative-syntax"> - <title>Alternative syntax for control structures</title> - <para> - PHP offers an alternative syntax for some of its control - structures; namely, <literal>if</literal>, - <literal>while</literal>, <literal>for</literal>, - <literal>foreach</literal>, and <literal>switch</literal>. - In each case, the basic form of the alternate syntax is to change - the opening brace to a colon (:) and the closing brace to - <literal>endif;</literal>, <literal>endwhile;</literal>, - <literal>endfor;</literal>, <literal>endforeach;</literal>, or - <literal>endswitch;</literal>, respectively. + </sect1> + <sect1 id="control-structures.alternative-syntax"> + <title>ì ì´êµ¬ì¡°ì ë¤ë¥¸ íí (Alternative syntax for control structures)</title> + <para> + PHPë ëë¶ë¶ì ì ì´êµ¬ì¡°ì ëí´ ê¸°ì¡´ì ë°©ë²ê³¼ë ë¤ë¥¸ íí ë°©ë²ì ì ê³µíë¤. + <literal>if</literal>, <literal>while</literal>, <literal>for</literal>, + <literal>foreach</literal>, <literal>switch</literal>ì 5ê°ì ì ì´êµ¬ì¡°ì ëí´, + ì¬ë ì¤ê´í¸({) ëì ì½ë¡ ( : )ì ì°ê³ , ë«ë ì¤ê´í¸(}) ëì ê°ê°ì ì ì´ êµ¬ì¡°ì ë°ë¼ + <literal>endif;</literal>ë, <literal>endwhile;</literal>,<literal>endfor;</literal>, + <literal>endforeach;</literal>, <literal>endswitch;</literal>를 ì ì´ì£¼ë©´ ëë¤. <informalexample> - <programlisting role="php"> + <programlisting role="php"> <?php if ($a == 5): ?> A is equal to 5 <?php endif; ?> </programlisting> - </informalexample> - </para> - <simpara> - In the above example, the HTML block "A = 5" is nested within an - <literal>if</literal> statement written in the alternative syntax. - The HTML block would be displayed only if $a is equal to 5. - </simpara> - <para> - The alternative syntax applies to <literal>else</literal> and - <literal>elseif</literal> as well. The following is an - <literal>if</literal> structure with <literal>elseif</literal> and - <literal>else</literal> in the alternative format: + </informalexample> + </para> + <simpara> + ìì ììì "A = 5"ë¼ë HTML ë¸ë¡ì´ <literal>if</literal>문 ìì ì¬ì©ëê³ ìë¤. + ìì HTML ë¸ë¡ì $aê° 5ì¼ ê²½ì°ìë§ íìëë¤. + </simpara> + <para> + ë¤ìê³¼ ê°ì´ <literal>else</literal>ì <literal>elseif</literal>ë ì¬ì©í ì ìë¤. : <informalexample> - <programlisting role="php"> + <programlisting role="php"> if ($a == 5): print "a equals 5"; print "..."; @@ -192,28 +184,27 @@ print "a is neither 5 nor 6"; endif; </programlisting> - </informalexample> - </para> - <para> - See also <link linkend="control-structures.while">while</link>, - <link linkend="control-structures.for">for</link>, and <link - linkend="control-structures.if">if</link> for further examples. - </para> - </sect1> - - <sect1 id="control-structures.while"> - <title><literal>while</literal></title> - <para> - <literal>while</literal> loops are the simplest type of loop in - PHP. They behave just like their C counterparts. The basic form - of a <literal>while</literal> statement is: + </informalexample> + </para> + <para> + ê°ê°ì ì ì´êµ¬ì¡°ì ëí ìì ë <link linkend="control-structures.while">while</link>, + <link linkend="control-structures.for">for</link>, <link linkend="control-structures.if">if</link>를 보기 ë°ëë¤. + </para> + </sect1> + <sect1 id="control-structures.while"> + <title> + <literal>while</literal> + </title> + <para> + <literal>while</literal> 루íë PHPì ê°ì¥ ê°ë¨í ì ì´êµ¬ì¡°ì´ë¤. + ì´ê²ì Cì ëì¼íê² ìëíë¤. <literal>while</literal>ì 기본 ííë ë¤ìê³¼ ê°ë¤. : <informalexample> - <programlisting> + <programlisting> while (expr) statement </programlisting> - </informalexample> - </para> - <simpara> + </informalexample> + </para> + <simpara> The meaning of a <literal>while</literal> statement is simple. It tells PHP to execute the nested statement(s) repeatedly, as long as the <literal>while</literal> expression evaluates to @@ -226,22 +217,22 @@ <literal>FALSE</literal> from the very beginning, the nested statement(s) won't even be run once. </simpara> - <para> + <para> Like with the <literal>if</literal> statement, you can group multiple statements within the same <literal>while</literal> loop by surrounding a group of statements with curly braces, or by using the alternate syntax: <informalexample> - <programlisting> + <programlisting> while (expr): statement ... endwhile; </programlisting> - </informalexample> - </para> - <para> + </informalexample> + </para> + <para> The following examples are identical, and both print numbers from 1 to 10: <informalexample> - <programlisting> + <programlisting> /* example 1 */ $i = 1; @@ -259,16 +250,16 @@ $i++; endwhile; </programlisting> - </informalexample> - </para> - </sect1> - - <sect1 id="control-structures.do.while"> - <title><literal>do..while</literal></title> - <simpara> - <literal>do..while</literal> loops are very similar to - <literal>while</literal> loops, except the truth expression is - checked at the end of each iteration instead of in the beginning. + </informalexample> + </para> + </sect1> + <sect1 id="control-structures.do.while"> + <title> + <literal>do..while</literal> + </title> + <simpara> + <literal>do..while</literal> 루íë ë¹êµìì´ ìì´ ìë 맨 ë¤ì ìë¤ë ì ì ì ì¸íë©´ + <literal>while</literal> 루íì ë¹ì·íë¤. The main difference from regular <literal>while</literal> loops is that the first iteration of a <literal>do..while</literal> loop is guarenteed to run (the truth expression is only checked at the end @@ -278,33 +269,34 @@ <literal>FALSE</literal> right from the beginning, the loop execution would end immediately). </simpara> - <para> + <para> There is just one syntax for <literal>do..while</literal> loops: <informalexample> - <programlisting role="php"> + <programlisting role="php"> $i = 0; do { print $i; } while ($i>0); </programlisting> - </informalexample> - </para> - <simpara> + </informalexample> + </para> + <simpara> The above loop would run one time exactly, since after the first iteration, when truth expression is checked, it evaluates to <literal>FALSE</literal> ($i is not bigger than 0) and the loop execution ends. </simpara> - <para> + <para> Advanced C users may be familiar with a different usage of the <literal>do..while</literal> loop, to allow stopping execution in the middle of code blocks, by encapsulating them with - <literal>do..while</literal>(0), and using the <link - linkend="control-structures.break"><literal>break</literal></link> + <literal>do..while</literal>(0), and using the <link linkend="control-structures.break"> + <literal>break</literal> + </link> statement. The following code fragment demonstrates this: <informalexample> - <programlisting role="php"> + <programlisting role="php"> do { if ($i < 5) { print "i is not big enough"; @@ -320,59 +312,48 @@ } while(0); </programlisting> - </informalexample> - </para> - <simpara> + </informalexample> + </para> + <simpara> Don't worry if you don't understand this right away or at all. You can code scripts and even powerful scripts without using this `feature'. </simpara> - </sect1> - - <sect1 id="control-structures.for"> - <title><literal>for</literal></title> - <para> - <literal>for</literal> loops are the most complex loops in PHP. - They behave like their C counterparts. The syntax of a - <literal>for</literal> loop is: + </sect1> + <sect1 id="control-structures.for"> + <title> + <literal>for</literal> + </title> + <para> + <literal>for</literal> 루íë PHPìì ê°ì¥ ë³µì¡í 루íì´ë¤. + ì´ê²ì ííì Cì ë§¤ì° ì ì¬íë¤. <literal>for</literal> 루íì 문ë²ì ë¤ìê³¼ ê°ë¤. : <informalexample> - <programlisting> + <programlisting> for (expr1; expr2; expr3) statement </programlisting> - </informalexample> - </para> - <simpara> - The first expression (<replaceable>expr1</replaceable>) is - evaluated (executed) once unconditionally at the beginning of the - loop. - </simpara> - <simpara> - In the beginning of each iteration, - <replaceable>expr2</replaceable> is evaluated. If it evaluates to - <literal>TRUE</literal>, the loop continues and the nested - statement(s) are executed. If it evaluates to - <literal>FALSE</literal>, the execution of the loop ends. - </simpara> - <simpara> - At the end of each iteration, <replaceable>expr3</replaceable> is - evaluated (executed). - </simpara> - <simpara> - Each of the expressions can be empty. - <replaceable>expr2</replaceable> being empty means the loop should - be run indefinitely (PHP implicitly considers it as - <literal>TRUE</literal>, like C). This may not be as useless as - you might think, since often you'd want to end the loop using a - conditional <link - linkend="control-structures.break"><literal>break</literal></link> - statement instead of using the <literal>for</literal> truth - expression. + </informalexample> + </para> + <simpara> + 첫 ë²ì§¸ ííì(<replaceable>expr1</replaceable>)ì 루í를 ììí ë 무조건 íë² íê°(ì¤í)ëë¤. + </simpara> + <simpara> + 매 ë°ë³µì ìì ëë§ë¤ <replaceable>expr2</replaceable>ê° íê°ëë¤. + ë§ì½ ì´ê²ì´ <literal>TRUE</literal>ë©´ 루íë ê³ìëê³ statementê° ì¤íëë¤. + <literal>FALSE</literal>ì´ë©´ 루íë ì¢ ë£ëë¤. + </simpara> + <simpara> + 매 ë°ë³µì´ ëë ë <replaceable>expr3</replaceable>ê° íê°(ì¤í)ëë¤. + </simpara> + <simpara> + ê° íê°ìì ë¹ìë ì ìë¤. <replaceable>expr2</replaceable>ê° ë¹ì´ìì¼ë©´ 무í 루í를 ë»íë¤. + (PHPë Cì ê°ì´ ë¹ì´ìì¼ë©´ TRUEë¡ ì¸ìíë¤.) + ì´ê±´ ë³ë¡ ì¢ì ë°©ë²ì´ ìëì§ë§, ì¢ ì¢ ì´ë ê² ì¬ì©íê³ <link linkend="control-structures.break"> + <literal>break</literal></link>를 ì¬ì©íì¬ ì¢ ë£íë ë°©ë²ë ìë¤. </simpara> - <para> - Consider the following examples. All of them display numbers from - 1 to 10: + <para> + ë¤ì ìë 1ìì 10ê¹ì§ ì¶ë ¥íë ìì ë¤ì´ë¤. : <informalexample> - <programlisting role="php"> + <programlisting role="php"> /* example 1 */ for ($i = 1; $i <= 10; $i++) { @@ -403,86 +384,75 @@ for ($i = 1; $i <= 10; print $i, $i++) ; </programlisting> - </informalexample> - </para> - <simpara> - Of course, the first example appears to be the nicest one (or - perhaps the fourth), but you may find that being able to use empty - expressions in <literal>for</literal> loops comes in handy in many - occasions. - </simpara> - <para> - PHP also supports the alternate "colon syntax" for - <literal>for</literal> loops. + </informalexample> + </para> + <simpara> + ë¬¼ë¡ ì²ìê²ì´ ê°ì¥ ì¢ìë³´ì¸ë¤. ê·¸ë¬ë ë머ì§ë ê°ë¥íë¤ë ê²ì ììì¼ íë¤. + </simpara> + <para> + PHPë <literal>for</literal> 루íì ëí´ìë ë¤ìê³¼ ê°ì "colon syntax"를 ì§ìíë¤. <informalexample> - <programlisting> + <programlisting> for (expr1; expr2; expr3): statement; ...; endfor; </programlisting> - </informalexample> - </para> - <para> + </informalexample> + </para> + <para> Other languages have a <literal>foreach</literal> statement to traverse an array or hash. PHP 3 has no such construct; PHP 4 does - (see <link - linkend="control-structures.foreach">foreach</link>). In PHP 3, you + (see <link linkend="control-structures.foreach">foreach</link>). In PHP 3, you can combine <link linkend="control-structures.while">while</link> with the <function>list</function> and <function>each</function> functions to achieve the same effect. See the documentation for these functions for an example. </para> - - </sect1> - <sect1 id="control-structures.foreach"> - <title><literal>foreach</literal></title> - <para> - PHP 4 (not PHP 3) includes a <literal>foreach</literal> construct, - much like perl and some other languages. This simply gives an easy - way to iterate over arrays. There are two syntaxes; the second is - a minor but useful extension of the first: + </sect1> + <sect1 id="control-structures.foreach"> + <title> + <literal>foreach</literal> + </title> + <para> + PHP4(PHP3ë ìëë¤)ë perl ë±ì ë¤ë¥¸ ì¸ì´ê° ì ê³µíë foreach 구조를 ì ê³µíë¤. + ì´ êµ¬ì¡°ë ë°°ì´ì ìì´ì ë°ë³µì ì¸ ìì ì íëë° ì ì©íë¤. + ì´ê²ìë ëê°ì§ 문ë²ì´ ìëë°, ë ë²ì§¸ ê²ì 첫 ë²ì§¸ ê²ì ë¶ë¶ íì¥ì´ë¼ê³ + ìê°í ì ìì¼ë ì¤ì ë¡ ë§¤ì° ì ì©íê² ì¬ì©ëë¤. <informalexample> - <programlisting> + <programlisting> foreach(array_expression as $value) statement foreach(array_expression as $key => $value) statement </programlisting> - </informalexample> - </para> - <simpara> - The first form loops over the array given by - <literal>array_expression</literal>. On each loop, the value of - the current element is assigned to <literal>$value</literal> and - the internal array pointer is advanced by one (so on the next - loop, you'll be looking at the next element). - </simpara> - <simpara> - The second form does the same thing, except that the current - element's key will be assigned to the variable - <literal>$key</literal> on each loop. - </simpara> - <para> - <note> - <para> - When <literal>foreach</literal> first starts executing, the - internal array pointer is automatically reset to the first element - of the array. This means that you do not need to call - <function>reset</function> before a <literal>foreach</literal> - loop. + </informalexample> + </para> + <simpara> + 첫 ë²ì§¸ 모ìì <literal>array_expression</literal> ì¼ë¡ 주ì´ì§ ë°°ì´ì ëí´ ë£¨í를 ìííë¤. + ê°ê°ì 루íìì ë´ìì, ë°°ì´ì ììë <literal>$value</literal>ì ì ì¥ëê³ + ë´ë¶ ë°°ì´ í¬ì¸í°(internal array pointer)ë íë ì ì§íì¬ ë¤ì ìì ìì ìë¡ì´ ìì를 ê°ì ¸ì¤ëë¡ íë¤. + </simpara> + <simpara> + ë ë²ì§¸ 모ìì 첫 ë²ì§¸ì ëì¼í ìì ì íì§ë§, <literal>$key</literal>ì í´ë¹ ììì í¤ê°ì ì ì¥íê² ëë¤. + </simpara> + <para> + <note> + <para> + <literal>foreach</literal> ë¬¸ì´ ì²ì ìíë ë, ë´ë¶ ë°°ì´ í¬ì¸í°(internal array pointer)ë + ìëì ì¼ë¡ ë°°ì´ì 첫ë²ì§¸ ììë¡ ì¤ì ëë¤. ì´ë§ì ì미ë ì¬ë¬ë¶ì´ <literal>foreach</literal>문ì ì¬ì©í ë + <function>reset</function>ì 미리 í¸ì¶í íìë ìë¤ë ê²ì´ë¤. </para> - </note> - </para> - <para> - <note> - <para> + </note> + </para> + <para> + <note> + <para> Also note that <literal>foreach</literal> operates on a copy of the specified array, not the array itself, therefore the array pointer is not modified like with the each construct. </para> - </note> - </para> - <para> - You may have noticed that the following are functionally - identical: + </note> + </para> + <para> + ìëì ë ê°ì 문ì¥ì ëì¼í 결과를 ë§ë ë¤ë ê²ì ì ì ìì ê²ì´ë¤. : <informalexample> - <programlisting role="php"> + <programlisting role="php"> reset ($arr); while (list(, $value) = each ($arr)) { echo "Value: $value<br>\n"; @@ -492,10 +462,10 @@ echo "Value: $value<br>\n"; } </programlisting> - </informalexample> - The following are also functionally identical: + </informalexample> + ë¤ì ë ê°ì 문ì¥ë 기ë¥ì ì¼ë¡ ëì¼íë¤. : <informalexample> - <programlisting role="php"> + <programlisting role="php"> reset ($arr); while (list($key, $value) = each ($arr)) { echo "Key: $key; Value: $value<br>\n"; @@ -505,12 +475,12 @@ echo "Key: $key; Value: $value<br>\n"; } </programlisting> - </informalexample> - </para> - <para> - Some more examples to demonstrate usages: + </informalexample> + </para> + <para> + ì¶ê°ì ì¼ë¡ ëª ê°ì ìì 를 ë³´ì. : <informalexample> - <programlisting role="php"> + <programlisting role="php"> /* foreach example 1: value only */ $a = array (1, 2, 3, 17); @@ -542,25 +512,24 @@ print "\$a[$k] => $v.\n"; } </programlisting> - </informalexample> - </para> - </sect1> - - <sect1 id="control-structures.break"> - <title><literal>break</literal></title> - <simpara> - <literal>break</literal> ends execution of the current - <literal>for</literal>, <literal>while</literal>, or - <literal>switch</literal> structure. + </informalexample> + </para> + </sect1> + <sect1 id="control-structures.break"> + <title> + <literal>break</literal> + </title> + <simpara> + <literal>break</literal>ë <literal>for</literal>ë, <literal>while</literal>, <literal>switch</literal>ìì ë¹ ì ¸ ëê°ë ëª ë ¹ì´ë¤. </simpara> - <simpara> - <literal>break</literal> accepts an optional numeric argument + <simpara> + <literal>break</literal> accepts an optional numeric argument which tells it how many nested enclosing structures are to be broken out of. </simpara> - <para> - <informalexample> - <programlisting role="php"> + <para> + <informalexample> + <programlisting role="php"> $arr = array ('one', 'two', 'three', 'four', 'stop', 'five'); while (list (, $val) = each ($arr)) { if ($val == 'stop') { @@ -585,25 +554,26 @@ } } </programlisting> - </informalexample> - </para> - </sect1> - - <sect1 id="control-structures.continue"> - <title><literal>continue</literal></title> - <simpara> - <literal>continue</literal> is used within looping structures to + </informalexample> + </para> + </sect1> + <sect1 id="control-structures.continue"> + <title> + <literal>continue</literal> + </title> + <simpara> + <literal>continue</literal> is used within looping structures to skip the rest of the current loop iteration and continue execution at the beginning of the next iteration. </simpara> - <simpara> - <literal>continue</literal> accepts an optional numeric argument + <simpara> + <literal>continue</literal> accepts an optional numeric argument which tells it how many levels of enclosing loops it should skip to the end of. </simpara> - <para> - <informalexample> - <programlisting role="php"> + <para> + <informalexample> + <programlisting role="php"> while (list ($key, $value) = each ($arr)) { if (!($key % 2)) { // skip odd members continue; @@ -625,27 +595,28 @@ echo "Neither does this.<br>\n"; } </programlisting> - </informalexample> - </para> - </sect1> - - <sect1 id="control-structures.switch"> - <title><literal>switch</literal></title> - <simpara> + </informalexample> + </para> + </sect1> + <sect1 id="control-structures.switch"> + <title> + <literal>switch</literal> + </title> + <simpara> The <literal>switch</literal> statement is similar to a series of IF statements on the same expression. In many occasions, you may want to compare the same variable (or expression) with many different values, and execute a different piece of code depending on which value it equals to. This is exactly what the <literal>switch</literal> statement is for. - </simpara> - <para> + </simpara> + <para> The following two examples are two different ways to write the same thing, one using a series of <literal>if</literal> statements, and the other using the <literal>switch</literal> statement: <informalexample> - <programlisting role="php"> + <programlisting role="php"> if ($i == 0) { print "i equals 0"; } @@ -668,9 +639,9 @@ break; } </programlisting> - </informalexample> - </para> - <para> + </informalexample> + </para> + <para> It is important to understand how the <literal>switch</literal> statement is executed in order to avoid mistakes. The <literal>switch</literal> statement executes line by line @@ -685,7 +656,7 @@ statement list, PHP will go on executing the statements of the following case. For example: <informalexample> - <programlisting role="php"> + <programlisting role="php"> switch ($i) { case 0: print "i equals 0"; @@ -695,9 +666,9 @@ print "i equals 2"; } </programlisting> - </informalexample> - </para> - <simpara> + </informalexample> + </para> + <simpara> Here, if $i equals to 0, PHP would execute all of the print statements! If $i equals to 1, PHP would execute the last two print statements, and only if $i equals to 2, you'd get the @@ -706,7 +677,7 @@ (even though you may want to avoid supplying them on purpose under certain circumstances). </simpara> - <simpara> + <simpara> In a <literal>switch</literal> statement, the condition is evaluated only once and the result is compared to each <literal>case</literal> statement. In an <literal>elseif</literal> @@ -714,11 +685,11 @@ more complicated than a simple compare and/or is in a tight loop, a <literal>switch</literal> may be faster. </simpara> - <para> + <para> The statement list for a case can also be empty, which simply passes control into the statement list for the next case. <informalexample> - <programlisting role="php"> + <programlisting role="php"> switch ($i) { case 0: case 1: @@ -729,13 +700,13 @@ print "i is 3"; } </programlisting> - </informalexample> - </para> - <para> + </informalexample> + </para> + <para> A special case is the default case. This case matches anything that wasn't matched by the other cases. For example: <informalexample> - <programlisting role="php"> + <programlisting role="php"> switch ($i) { case 0: print "i equals 0"; @@ -750,21 +721,20 @@ print "i is not equal to 0, 1 or 2"; } </programlisting> - </informalexample> - </para> - <para> + </informalexample> + </para> + <para> The <literal>case</literal> expression may be any expression that evaluates to a simple type, that is, integer or floating-point numbers and strings. Arrays or objects cannot be used here unless they are dereferenced to a simple type. </para> - <para> + <para> The alternative syntax for control structures is supported with - switches. For more information, see <link - linkend="control-structures.alternative-syntax">Alternative syntax + switches. For more information, see <link linkend="control-structures.alternative-syntax">Alternative syntax for control structures</link> . <informalexample> - <programlisting role="php"> + <programlisting role="php"> switch ($i): case 0: print "i equals 0"; @@ -779,36 +749,36 @@ print "i is not equal to 0, 1 or 2"; endswitch; </programlisting> - </informalexample> - </para> - </sect1> - - <sect1 id="function.require"> - <title><function>require</function></title> - <simpara> + </informalexample> + </para> + </sect1> + <sect1 id="function.require"> + <title> + <function>require</function> + </title> + <simpara> The <function>require</function> statement replaces itself with the specified file, much like the C preprocessor's <literal>#include</literal> works. </simpara> - <simpara> + <simpara> If "URL fopen wrappers" are enabled in PHP (which they are in the default configuration), you can specify the file to be <function>require</function>ed using an URL instead of a local pathname. See <link linkend="features.remote-files">Remote files</link> and <function>fopen</function> for more information. </simpara> - <simpara> + <simpara> An important note about how this works is that when a file is <function>include</function>ed or <function>require</function>ed, parsing drops out of PHP mode and into HTML mode at the beginning of the target file, and resumes PHP mode again at the end. For this reason, any code inside the target file which should be - executed as PHP code must be enclosed within <link - linkend="language.basic-syntax.phpmode">valid PHP start and end + executed as PHP code must be enclosed within <link linkend="language.basic-syntax.phpmode">valid PHP start and end tags</link>. </simpara> - <simpara> - <function>require</function> is not actually a function in PHP; + <simpara> + <function>require</function> is not actually a function in PHP; rather, it is a language construct. It is subject to some different rules than functions are. For instance, <function>require</function> is not subject to any containing @@ -816,7 +786,7 @@ attempting to read a return value from a <function>require</function> call results in a parse error. </simpara> - <simpara> + <simpara> Unlike <function>include</function>, <function>require</function> will <emphasis>always</emphasis> read in the target file, <emphasis>even if the line it's on never executes</emphasis>. If @@ -826,24 +796,24 @@ which the <function>require</function> occurs is not executed, neither will any of the code in the target file be executed. </simpara> - <simpara> + <simpara> Similarly, looping structures do not affect the behaviour of <function>require</function>. Although the code contained in the target file is still subject to the loop, the <function>require</function> itself happens only once. </simpara> - <para> + <para> This means that you can't put a <function>require</function> statement inside of a loop structure and expect it to include the contents of a different file on each iteration. To do that, use an <function>include</function> statement. <informalexample> - <programlisting role="php"> + <programlisting role="php"> require ('header.inc'); </programlisting> - </informalexample> - </para> - <simpara> + </informalexample> + </para> + <simpara> When a file is <function>require</function>ed, the code it contains inherits the variable scope of the line on which the <function>require</function> occurs. Any variables available at @@ -853,7 +823,7 @@ in the called file will behave as though it had been defined inside that function. </simpara> - <para> + <para> If the <function>require</function>ed file is called via HTTP using the fopen wrappers, and if the target server interprets the target file as PHP code, variables may be passed to the @@ -864,7 +834,7 @@ on the remote server and the result is then being included into the local script. <informalexample> - <programlisting role="php"> + <programlisting role="php"> /* This example assumes that someserver is configured to parse .php * files and not .txt files. Also, 'works' here means that the variables * $varone and $vartwo are available within the require()ed file. */ @@ -884,9 +854,9 @@ require ("file.txt"); /* Works. */ require ("file.php"); /* Works. */ </programlisting> - </informalexample> - </para> - <simpara> + </informalexample> + </para> + <simpara> In PHP 3, it is possible to execute a <literal>return</literal> statement inside a <function>require</function>ed file, as long as that statement occurs in the global scope of the @@ -895,67 +865,66 @@ has been discontinued. If you need this functionality, see <function>include</function>. </simpara> - <simpara> + <simpara> See also <function>include</function>, <function>require_once</function>, <function>include_once</function>, <function>readfile</function>, and <function>virtual</function>. </simpara> - </sect1> - - <sect1 id="function.include"> - <title><function>include</function></title> - <simpara> + </sect1> + <sect1 id="function.include"> + <title> + <function>include</function> + </title> + <simpara> The <function>include</function> statement includes and evaluates the specified file. </simpara> - <simpara> + <simpara> If "URL fopen wrappers" are enabled in PHP (which they are in the default configuration), you can specify the file to be <function>include</function>ed using an URL instead of a local pathname. See <link linkend="features.remote-files">Remote files</link> and <function>fopen</function> for more information. </simpara> - <simpara> + <simpara> An important note about how this works is that when a file is <function>include</function>ed or <function>require</function>ed, parsing drops out of PHP mode and into HTML mode at the beginning of the target file, and resumes again at the end. For this reason, any code inside the target file which should be executed as PHP - code must be enclosed within <link - linkend="language.basic-syntax.phpmode">valid PHP start and end + code must be enclosed within <link linkend="language.basic-syntax.phpmode">valid PHP start and end tags</link>. </simpara> - <para> + <para> This happens each time the <function>include</function> statement is encountered, so you can use an <function>include</function> statement within a looping structure to include a number of different files. <informalexample> - <programlisting role="php"> + <programlisting role="php"> $files = array ('first.inc', 'second.inc', 'third.inc'); for ($i = 0; $i < count($files); $i++) { include $files[$i]; } </programlisting> - </informalexample> - </para> - <para> - <function>include</function> differs from + </informalexample> + </para> + <para> + <function>include</function> differs from <function>require</function> in that the include statement is re-evaluated each time it is encountered (and only when it is being executed), whereas the <function>require</function> statement is replaced by the required file when it is first encountered, whether the contents of the file will be evaluated or - not (for example, if it is inside an <link - linkend="control-structures.if">if</link> statement whose + not (for example, if it is inside an <link linkend="control-structures.if">if</link> statement whose condition evaluated to false). </para> - <para> + <para> Because <function>include</function> is a special language construct, you must enclose it within a statement block if it is inside a conditional block. <informalexample> - <programlisting role="php"> + <programlisting role="php"> /* This is WRONG and will not work as desired. */ if ($condition) @@ -971,9 +940,9 @@ include($other); } </programlisting> - </informalexample> - </para> - <simpara> + </informalexample> + </para> + <simpara> In both PHP 3 and PHP 4, it is possible to execute a <literal>return</literal> statement inside an <function>include</function>ed file, in order to terminate @@ -988,9 +957,10 @@ the <function>include</function> call as you would a normal function. This generates a parse error in PHP 3. </simpara> - <example> - <title><function>include</function> in PHP 3 and PHP 4</title> - <para> + <example> + <title> + <function>include</function> in PHP 3 and PHP 4</title> + <para> Assume the existence of the following file (named <filename>test.inc</filename>) in the same directory as the main file: @@ -1003,8 +973,8 @@ echo "After the return <br>\n"; ?> </programlisting> - </para> - <para> + </para> + <para> Assume that the main file (<filename>main.html</filename>) contains the following: <programlisting role="php"> @@ -1013,8 +983,8 @@ echo "File returned: '$retval'<br>\n"; ?> </programlisting> - </para> - <para> + </para> + <para> When <filename>main.html</filename> is called in PHP 3, it will generate a parse error on line 2; you can't take the value of an <function>include</function> in PHP 3. In PHP 4, however, the @@ -1023,8 +993,8 @@ Before the return File returned: '27' </screen> - </para> - <para> + </para> + <para> Now, assume that <filename>main.html</filename> has been altered to contain the following: <programlisting role="php"> @@ -1033,8 +1003,8 @@ echo "Back in main.html<br>\n"; ?> </programlisting> - </para> - <para> + </para> + <para> In PHP 4, the output will be: <screen> Before the return @@ -1047,8 +1017,8 @@ Parse error: parse error in /home/torben/public_html/phptest/main.html on line 5 </screen> - </para> - <para> + </para> + <para> The above parse error is a result of the fact that the <literal>return</literal> statement is enclosed in a non-function block within <filename>test.inc</filename>. When the return is @@ -1057,13 +1027,13 @@ Before the return 27Back in main.html </screen> - </para> - <para> + </para> + <para> The spurious '27' is due to the fact that PHP 3 does not support <literal>return</literal>ing values from files like that. </para> - </example> - <simpara> + </example> + <simpara> When a file is <function>include</function>ed, the code it contains inherits the variable scope of the line on which the <function>include</function> occurs. Any variables available at @@ -1073,7 +1043,7 @@ in the called file will behave as though it had been defined inside that function. </simpara> - <para> + <para> If the <function>include</function>ed file is called via HTTP using the fopen wrappers, and if the target server interprets the target file as PHP code, variables may be passed to the @@ -1084,7 +1054,7 @@ on the remote server and the result is then being included into the local script. <informalexample> - <programlisting role="php"> + <programlisting role="php"> /* This example assumes that someserver is configured to parse .php * files and not .txt files. Also, 'works' here means that the variables * $varone and $vartwo are available within the include()ed file. */ @@ -1104,18 +1074,19 @@ include ("file.txt"); /* Works. */ include ("file.php"); /* Works. */ </programlisting> - </informalexample> - </para> - <simpara> + </informalexample> + </para> + <simpara> See also <function>require</function>, <function>require_once</function>, <function>include_once</function>, <function>readfile</function>, and <function>virtual</function>. </simpara> - </sect1> - - <sect1 id="function.require-once"> - <title><function>require_once</function></title> - <para> + </sect1> + <sect1 id="function.require-once"> + <title> + <function>require_once</function> + </title> + <para> The <function>require_once</function> statement replaces itself with the specified file, much like the C preprocessor's <literal>#include</literal> works, and in that respect is @@ -1125,12 +1096,12 @@ added to your script only once, and avoid clashes with variable values or function names that can happen. </para> - <para> + <para> For example, if you create the following 2 include files <literal>utils.inc</literal> and <literal>foolib.inc</literal> - <example> - <title>utils.inc</title> - <programlisting role="php"> + <example> + <title>utils.inc</title> + <programlisting role="php"> <?php define(PHPVERSION, floor(phpversion())); echo "GLOBALS ARE NICE\n"; @@ -1139,10 +1110,10 @@ } ?> </programlisting> - </example> - <example> - <title>foolib.inc</title> - <programlisting role="php"> + </example> + <example> + <title>foolib.inc</title> + <programlisting role="php"> <?php require ("utils.inc"); function showVar($var) { @@ -1156,11 +1127,11 @@ // bunch of other functions ... ?> </programlisting> - </example> + </example> And then you write a script <literal>cause_error_require.php</literal> - <example> - <title>cause_error_require.php</title> - <programlisting role="php"> + <example> + <title>cause_error_require.php</title> + <programlisting role="php"> <?php require("foolib.inc"); /* the following will generate an error */ @@ -1173,44 +1144,44 @@ showVar($foo); ?> </programlisting> - </example> + </example> When you try running the latter one, the resulting ouptut will be (using PHP 4.01pl2): <informalexample> - <programlisting> + <programlisting> GLOBALS ARE NICE GLOBALS ARE NICE Fatal error: Cannot redeclare goodTea() in utils.inc on line 5 </programlisting> - </informalexample> + </informalexample> By modifying <literal>foolib.inc</literal> and <literal>cause_errror_require.php</literal> to use <function>require_once</function> instead of <function>require</function> and renaming the last one to <literal>avoid_error_require_once.php</literal>, we have: <example> - <title>foolib.inc (fixed)</title> - <programlisting role="php"> + <title>foolib.inc (fixed)</title> + <programlisting role="php"> ... require_once("utils.inc"); function showVar($var) { ... </programlisting> - </example> - <example> - <title>avoid_error_require_once.php</title> - <programlisting role="php"> + </example> + <example> + <title>avoid_error_require_once.php</title> + <programlisting role="php"> ... require_once("foolib.inc"); require_once("utils.inc"); $foo = array("1",array("complex","quaternion")); ... </programlisting> - </example> + </example> And when running the latter, the output will be (using PHP 4.0.1pl2): <informalexample> - <programlisting> + <programlisting> GLOBALS ARE NICE this is requiring globals.inc again which is also required in foolib.inc @@ -1227,9 +1198,9 @@ ) </programlisting> - </informalexample> - </para> - <para> + </informalexample> + </para> + <para> Also note that, analogous to the behavior of the <literal>#include</literal> of the C preprocessor, this statement acts at "compile time", e.g. when the script is parsed and before it @@ -1238,30 +1209,31 @@ <function>include_once</function> or <function>include</function> for that purpose. </para> - <para> + <para> For more examples on using <function>require_once</function> and <function>include_once</function>, look at the PEAR code included in the latest PHP source code distributions. </para> - <para> + <para> See also: <function>require</function>, <function>include</function>, <function>include_once</function>, <function>get_required_files</function>, <function>get_included_files</function>, <function>readfile</function>, and <function>virtual</function>. </para> - </sect1> - - <sect1 id="function.include-once"> - <title><function>include_once</function></title> - <para> + </sect1> + <sect1 id="function.include-once"> + <title> + <function>include_once</function> + </title> + <para> The <function>include_once</function> statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the <function>include</function> statement, with the important difference that if the code from a file has already been included, it will not be included again. </para> - <para> + <para> As mentioned in the <function>require_once</function> description, the <function>include_once</function> should be used in the cases in which the same file might be included and evaluated more than once during a @@ -1269,26 +1241,24 @@ included exactly once to avoid problems with function redefinitions, variable value reassignments, etc. </para> - <para> + <para> For more examples on using <function>require_once</function> and <function>include_once</function>, look at the PEAR code included in the latest PHP source code distributions. </para> - <para> - <function>include_once</function> was added in PHP 4.0.1pl2 + <para> + <function>include_once</function> was added in PHP 4.0.1pl2 </para> - <para> + <para> See also: <function>require</function>, <function>include</function>, <function>require_once</function>, <function>get_required_files</function>, <function>get_included_files</function>, <function>readfile</function>, and <function>virtual</function>. </para> - </sect1> - - </chapter> - - <!-- Keep this comment at the end of the file + </sect1> +</chapter> +<!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t Index: phpdoc/kr/language/expressions.xml diff -u phpdoc/kr/language/expressions.xml:1.2 phpdoc/kr/language/expressions.xml:1.3 --- phpdoc/kr/language/expressions.xml:1.2 Tue Jan 9 16:41:17 2001 +++ phpdoc/kr/language/expressions.xml Wed Jan 10 02:54:00 2001 @@ -1,38 +1,28 @@ - <chapter id="language.expressions"> - <title>Expressions</title> - - <simpara> - Expressions are the most important building stones of PHP. In PHP, - almost anything you write is an expression. The simplest yet - most accurate way to define an expression is "anything that has a - value".</simpara> - - <simpara> - The most basic forms of expressions are constants and variables. - When you type "$a = 5", you're assigning '5' into $a. '5', obviously, - has the value 5, or in other words '5' is an expression with the - value of 5 (in this case, '5' is an integer constant).</simpara> - - <simpara> - After this assignment, you'd expect $a's value to be 5 as - well, so if you wrote $b = $a, you'd expect it to behave just as - if you wrote $b = 5. In other words, $a is an expression with the - value of 5 as well. If everything works right, this is exactly - what will happen.</simpara> - - <para> - Slightly more complex examples for expressions are functions. For - instance, consider the following function: - +<chapter id="language.expressions"> + <title>ííì (Expressions)</title> + <simpara> + ííìì PHPìì ë§¤ì° ì¤ìí ë´ì©ì´ë¤. + PHPìì ì¬ë¬ë¶ì´ ìì±íë ê±°ì 모ë ê²ì ííìì´ë¤. + ê°ë¨í ííìì ì ì를 ìë°íê² ë§íë¤ë©´ "ê°ì ê°ì§ê³ ìë 모ë ê²"("anything that has a value")ì´ë¤. + </simpara> + <simpara> + ê°ë¨í ìì ë¡ "$a = 5"ì ê°ì ê²ì´ ìë¤. ì´ê²ì '5'ë¼ë ê°ì $aë¼ë ë³ìì ëì íë 문ì¥ì´ë¤. + ì¬ê¸°ì '5'ë¼ë ííìì ê° 5 ë¼ë ìë¯¸ê° ëë¤. + </simpara> + <simpara> + ìì ë¬¸ì¥ ë¤ìì "$b = $a"ë¼ë 문ì¥ì´ ìë¤ë©´, ì¬ê¸°ì $aë¼ë ííìì ê·¸ ë³ìê° ê°ì§ 5ë¼ë ê°ì íííë¤. + </simpara> + <para> + ì¡°ê¸ ë³µì¡í ê²½ì°ë í¨ìì´ë¤. ë¤ì í¨ì를 ë³´ì. : <informalexample> - <programlisting> + <programlisting> function foo () { return 5; } </programlisting> - </informalexample></para> - - <simpara> + </informalexample> + </para> + <simpara> Assuming you're familiar with the concept of functions (if you're not, take a look at the chapter about functions), you'd assume that typing <literal>$c = foo()</literal> is essentially just like @@ -40,8 +30,7 @@ are expressions with the value of their return value. Since foo() returns 5, the value of the expression 'foo()' is 5. Usually functions don't just return a static value but compute something.</simpara> - - <simpara> + <simpara> Of course, values in PHP don't have to be integers, and very often they aren't. PHP supports three scalar value types: integer values, floating point values and string values (scalar values are values that @@ -49,8 +38,7 @@ PHP also supports two composite (non-scalar) types: arrays and objects. Each of these value types can be assigned into variables or returned from functions.</simpara> - - <simpara> + <simpara> So far, users of PHP/FI 2 shouldn't feel any change. However, PHP takes expressions much further, in the same way many other languages do. PHP is an expression-oriented language, in the @@ -66,8 +54,7 @@ '$b = ($a = 5)' is like writing '$a = 5; $b = 5;' (a semicolon marks the end of a statement). Since assignments are parsed in a right to left order, you can also write '$b = $a = 5'.</simpara> - - <simpara> + <simpara> Another good example of expression orientation is pre- and post-increment and decrement. Users of PHP/FI 2 and many other languages may be familiar with the notation of variable++ and @@ -86,8 +73,7 @@ written '$variable++' evaluates to the original value of $variable, before it was incremented (PHP increments the variable after reading its value, thus the name 'post-increment').</simpara> - - <simpara> + <simpara> A very common type of expressions are comparison expressions. These expressions evaluate to either 0 or 1, meaning FALSE or TRUE (respectively). PHP supports > (bigger than), >= (bigger than @@ -95,8 +81,7 @@ (smaller than or equal to). These expressions are most commonly used inside conditional execution, such as <literal>if</literal> statements.</simpara> - - <simpara> + <simpara> The last example of expressions we'll deal with here is combined operator-assignment expressions. You already know that if you want to increment $a by 1, you can simply write '$a++' or '++$a'. @@ -117,26 +102,26 @@ assigned into $a). Any two-place operator can be used in this operator-assignment mode, for example '$a -= 5' (subtract 5 from the value of $a), '$b *= 7' (multiply the value of $b by 7), etc.</simpara> - - <para> + <para> There is one more expression that may seem odd if you haven't seen it in other languages, the ternary conditional operator: - <informalexample><programlisting> + <informalexample> + <programlisting> $first ? $second : $third -</programlisting></informalexample> +</programlisting> + </informalexample> If the value of the first subexpression is true (non-zero), then it the second subexpression is evaluated, and that is the result of the conditional expression. Otherwise, the third subexpression is evaluated, and that is the value.</para> - - <para> + <para> The following example should help you understand pre- and post-increment and expressions in general a bit better: <informalexample> - <programlisting> + <programlisting> function double($i) { return $i*2; } @@ -156,9 +141,10 @@ value of 24. the value of the assignment (24) is then assigned into $h, and $h ends with the value of 24 as well. */ -</programlisting></informalexample></para> - - <simpara> +</programlisting> + </informalexample> + </para> + <simpara> In the beginning of the chapter we said that we'll be describing the various statement types, and as promised, expressions can be statements. However, not every expression is a statement. In @@ -166,8 +152,7 @@ expression followed by a semicolon. In '$b=$a=5;', $a=5 is a valid expression, but it's not a statement by itself. '$b=$a=5;' however is a valid statement.</simpara> - - <simpara> + <simpara> One last thing worth mentioning is the truth value of expressions. In many events, mainly in conditional execution and loops, you're not interested in the specific value of the expression, but only @@ -180,18 +165,15 @@ With non-scalar values (arrays and objects) - if the value contains no elements it's considered FALSE, otherwise it's considered TRUE.</simpara> - - <simpara> + <simpara> PHP provides a full and powerful implementation of expressions, and documenting it entirely goes beyond the scope of this manual. The above examples should give you a good idea about what expressions are and how you can construct useful expressions. Throughout the rest of this manual we'll write <replaceable>expr</replaceable> to indicate any valid PHP expression.</simpara> - - </chapter> - - <!-- Keep this comment at the end of the file +</chapter> +<!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t
Index: phpdoc/kr/language/control-structures.xml diff -u phpdoc/kr/language/control-structures.xml:1.2 phpdoc/kr/language/control-structures.xml:1.3 --- phpdoc/kr/language/control-structures.xml:1.2 Tue Jan 9 16:41:17 2001 +++ phpdoc/kr/language/control-structures.xml Wed Jan 10 02:54:00 2001 @@ -1,49 +1,48 @@ - <chapter id="control-structures"> - <title>Control Structures</title> - - <simpara> - Any PHP script is built out of a series of statements. A statement - can be an assignment, a function call, a loop, a conditional - statement of even a statement that does nothing (an empty - statement). Statements usually end with a semicolon. In addition, - statements can be grouped into a statement-group by encapsulating a - group of statements with curly braces. A statement-group is a - statement by itself as well. The various statement types are - described in this chapter. +<chapter id="control-structures"> + <title>ì ì´ êµ¬ì¡° (Control Structures)</title> + <simpara> + 모ë PHP ì¤í¬ë¦½í¸ë ì¼ë ¨ì 구문ì¼ë¡ ì´ë£¨ì´ ì§ë¤. + íëì 구문ì ëì ë¬¸ì´ ë ìë ìê³ , í¨ì í¸ì¶, ë°ë³µë¬¸, ì¡°ê±´ë¬¸ì´ ë ìë ìì¼ë©° + ì¬ì§ì´ë ì무 ë´ì©ì´ ìë ë¹ ë¬¸ì¥ì¼ ìë ìë¤. + í 구문ì ì¼ë°ì ì¼ë¡ ì¸ë¯¸ì½ë¡ (;)ì¼ë¡ ëëë¤. + ëí ì¬ë¬ê°ì 구문ì ì¤ê´í¸({,})를 ì¬ì©íì¬ íëì 그룹ì¼ë¡ ë§ë¤ì´ ì¬ì©í ìë ìë¤. + ì´ êµ¬ë¬¸-그룹ì ê·¸ 그룹ì 모ë 구문ë¤ì´ íëì êµ¬ë¬¸ì¸ ê²ì²ë¼ ì¸ìëë¤. + ì¬ê¸°ìë ì¬ë¬ ê°ì§ 구문ííì ëí´ ìì본ë¤. </simpara> - - <sect1 id="control-structures.if"> - <title><literal>if</literal></title> - <para> + <sect1 id="control-structures.if"> + <title> + <literal>if</literal> + </title> + <para> The <literal>if</literal> construct is one of the most important features of many languages, PHP included. It allows for - conditional execution of code fragments. PHP features an - <literal>if</literal> structure that is similar to that of C: + conditional execution of code fragments. + PHPì <literal>if</literal> 문ì Cì ë¹ì·íë¤.: <informalexample> - <programlisting> + <programlisting> if (expr) statement </programlisting> - </informalexample> - </para> - <simpara> + </informalexample> + </para> + <simpara> As described in the section about expressions, expr is evaluated to its truth value. If <replaceable>expr</replaceable> evaluates to <literal>TRUE</literal>, PHP will execute statement, and if it evaluates to <literal>FALSE</literal> - it'll ignore it. </simpara> - <para> + <para> The following example would display <computeroutput>a is bigger than b</computeroutput> if <replaceable>$a</replaceable> is bigger than <replaceable>$b</replaceable>: <informalexample> - <programlisting role="php"> + <programlisting role="php"> if ($a > $b) print "a is bigger than b"; </programlisting> - </informalexample> - </para> - <para> + </informalexample> + </para> + <para> Often you'd want to have more than one statement to be executed conditionally. Of course, there's no need to wrap each statement with an <literal>if</literal> clause. Instead, you can group @@ -53,25 +52,26 @@ <replaceable>$b</replaceable>, and would then assign the value of <replaceable>$a</replaceable> into <replaceable>$b</replaceable>: <informalexample> - <programlisting role="php"> + <programlisting role="php"> if ($a > $b) { print "a is bigger than b"; $b = $a; } </programlisting> - </informalexample> - </para> - <simpara> + </informalexample> + </para> + <simpara> If statements can be nested indefinitely within other <literal>if</literal> statements, which provides you with complete flexibility for conditional execution of the various parts of your program. </simpara> - </sect1> - - <sect1 id="control-structures.else"> - <title><literal>else</literal></title> - <para> + </sect1> + <sect1 id="control-structures.else"> + <title> + <literal>else</literal> + </title> + <para> Often you'd want to execute a statement if a certain condition is met, and a different statement if the condition is not met. This is what <literal>else</literal> is for. <literal>else</literal> @@ -83,29 +83,29 @@ <replaceable>$b</replaceable>, and <computeroutput>a is NOT bigger than b</computeroutput> otherwise: <informalexample> - <programlisting role="php"> + <programlisting role="php"> if ($a > $b) { print "a is bigger than b"; } else { print "a is NOT bigger than b"; } </programlisting> - </informalexample> + </informalexample> The <literal>else</literal> statement is only executed if the <literal>if</literal> expression evaluated to <literal>FALSE</literal>, and if there were any <literal>elseif</literal> expressions - only if they evaluated to - <literal>FALSE</literal> as well (see <link - linkend="control-structures.elseif">elseif</link>). + <literal>FALSE</literal> as well (see <link linkend="control-structures.elseif">elseif</link>). </para> - </sect1> - - <sect1 id="control-structures.elseif"> - <title><literal>elseif</literal></title> - <para> - <literal>elseif</literal>, as its name suggests, is a combination + </sect1> + <sect1 id="control-structures.elseif"> + <title> + <literal>elseif</literal> + </title> + <para> + <literal>elseif</literal>, as its name suggests, is a combination of <literal>if</literal> and <literal>else</literal>. Like <literal>else</literal>, it extends an <literal>if</literal> statement to execute a different statement in case the original @@ -118,7 +118,7 @@ b</computeroutput>, <computeroutput>a equal to b</computeroutput> or <computeroutput>a is smaller than b</computeroutput>: <informalexample> - <programlisting role="php"> + <programlisting role="php"> if ($a > $b) { print "a is bigger than b"; } elseif ($a == $b) { @@ -127,9 +127,9 @@ print "a is smaller than b"; } </programlisting> - </informalexample> - </para> - <simpara> + </informalexample> + </para> + <simpara> There may be several <literal>elseif</literal>s within the same <literal>if</literal> statement. The first <literal>elseif</literal> expression (if any) that evaluates to @@ -140,7 +140,7 @@ behavior) but the bottom line is that both would result in exactly the same behavior. </simpara> - <simpara> + <simpara> The <literal>elseif</literal> statement is only executed if the preceding <literal>if</literal> expression and any preceding <literal>elseif</literal> expressions evaluated to @@ -148,40 +148,32 @@ <literal>elseif</literal> expression evaluated to <literal>TRUE</literal>. </simpara> - </sect1> - - <sect1 id="control-structures.alternative-syntax"> - <title>Alternative syntax for control structures</title> - <para> - PHP offers an alternative syntax for some of its control - structures; namely, <literal>if</literal>, - <literal>while</literal>, <literal>for</literal>, - <literal>foreach</literal>, and <literal>switch</literal>. - In each case, the basic form of the alternate syntax is to change - the opening brace to a colon (:) and the closing brace to - <literal>endif;</literal>, <literal>endwhile;</literal>, - <literal>endfor;</literal>, <literal>endforeach;</literal>, or - <literal>endswitch;</literal>, respectively. + </sect1> + <sect1 id="control-structures.alternative-syntax"> + <title>ì ì´êµ¬ì¡°ì ë¤ë¥¸ íí (Alternative syntax for control structures)</title> + <para> + PHPë ëë¶ë¶ì ì ì´êµ¬ì¡°ì ëí´ ê¸°ì¡´ì ë°©ë²ê³¼ë ë¤ë¥¸ íí ë°©ë²ì ì ê³µíë¤. + <literal>if</literal>, <literal>while</literal>, <literal>for</literal>, + <literal>foreach</literal>, <literal>switch</literal>ì 5ê°ì ì ì´êµ¬ì¡°ì ëí´, + ì¬ë ì¤ê´í¸({) ëì ì½ë¡ ( : )ì ì°ê³ , ë«ë ì¤ê´í¸(}) ëì ê°ê°ì ì ì´ êµ¬ì¡°ì ë°ë¼ + <literal>endif;</literal>ë, <literal>endwhile;</literal>,<literal>endfor;</literal>, + <literal>endforeach;</literal>, <literal>endswitch;</literal>를 ì ì´ì£¼ë©´ ëë¤. <informalexample> - <programlisting role="php"> + <programlisting role="php"> <?php if ($a == 5): ?> A is equal to 5 <?php endif; ?> </programlisting> - </informalexample> - </para> - <simpara> - In the above example, the HTML block "A = 5" is nested within an - <literal>if</literal> statement written in the alternative syntax. - The HTML block would be displayed only if $a is equal to 5. - </simpara> - <para> - The alternative syntax applies to <literal>else</literal> and - <literal>elseif</literal> as well. The following is an - <literal>if</literal> structure with <literal>elseif</literal> and - <literal>else</literal> in the alternative format: + </informalexample> + </para> + <simpara> + ìì ììì "A = 5"ë¼ë HTML ë¸ë¡ì´ <literal>if</literal>문 ìì ì¬ì©ëê³ ìë¤. + ìì HTML ë¸ë¡ì $aê° 5ì¼ ê²½ì°ìë§ íìëë¤. + </simpara> + <para> + ë¤ìê³¼ ê°ì´ <literal>else</literal>ì <literal>elseif</literal>ë ì¬ì©í ì ìë¤. : <informalexample> - <programlisting role="php"> + <programlisting role="php"> if ($a == 5): print "a equals 5"; print "..."; @@ -192,28 +184,27 @@ print "a is neither 5 nor 6"; endif; </programlisting> - </informalexample> - </para> - <para> - See also <link linkend="control-structures.while">while</link>, - <link linkend="control-structures.for">for</link>, and <link - linkend="control-structures.if">if</link> for further examples. - </para> - </sect1> - - <sect1 id="control-structures.while"> - <title><literal>while</literal></title> - <para> - <literal>while</literal> loops are the simplest type of loop in - PHP. They behave just like their C counterparts. The basic form - of a <literal>while</literal> statement is: + </informalexample> + </para> + <para> + ê°ê°ì ì ì´êµ¬ì¡°ì ëí ìì ë <link linkend="control-structures.while">while</link>, + <link linkend="control-structures.for">for</link>, <link linkend="control-structures.if">if</link>를 보기 ë°ëë¤. + </para> + </sect1> + <sect1 id="control-structures.while"> + <title> + <literal>while</literal> + </title> + <para> + <literal>while</literal> 루íë PHPì ê°ì¥ ê°ë¨í ì ì´êµ¬ì¡°ì´ë¤. + ì´ê²ì Cì ëì¼íê² ìëíë¤. <literal>while</literal>ì 기본 ííë ë¤ìê³¼ ê°ë¤. : <informalexample> - <programlisting> + <programlisting> while (expr) statement </programlisting> - </informalexample> - </para> - <simpara> + </informalexample> + </para> + <simpara> The meaning of a <literal>while</literal> statement is simple. It tells PHP to execute the nested statement(s) repeatedly, as long as the <literal>while</literal> expression evaluates to @@ -226,22 +217,22 @@ <literal>FALSE</literal> from the very beginning, the nested statement(s) won't even be run once. </simpara> - <para> + <para> Like with the <literal>if</literal> statement, you can group multiple statements within the same <literal>while</literal> loop by surrounding a group of statements with curly braces, or by using the alternate syntax: <informalexample> - <programlisting> + <programlisting> while (expr): statement ... endwhile; </programlisting> - </informalexample> - </para> - <para> + </informalexample> + </para> + <para> The following examples are identical, and both print numbers from 1 to 10: <informalexample> - <programlisting> + <programlisting> /* example 1 */ $i = 1; @@ -259,16 +250,16 @@ $i++; endwhile; </programlisting> - </informalexample> - </para> - </sect1> - - <sect1 id="control-structures.do.while"> - <title><literal>do..while</literal></title> - <simpara> - <literal>do..while</literal> loops are very similar to - <literal>while</literal> loops, except the truth expression is - checked at the end of each iteration instead of in the beginning. + </informalexample> + </para> + </sect1> + <sect1 id="control-structures.do.while"> + <title> + <literal>do..while</literal> + </title> + <simpara> + <literal>do..while</literal> 루íë ë¹êµìì´ ìì´ ìë 맨 ë¤ì ìë¤ë ì ì ì ì¸íë©´ + <literal>while</literal> 루íì ë¹ì·íë¤. The main difference from regular <literal>while</literal> loops is that the first iteration of a <literal>do..while</literal> loop is guarenteed to run (the truth expression is only checked at the end @@ -278,33 +269,34 @@ <literal>FALSE</literal> right from the beginning, the loop execution would end immediately). </simpara> - <para> + <para> There is just one syntax for <literal>do..while</literal> loops: <informalexample> - <programlisting role="php"> + <programlisting role="php"> $i = 0; do { print $i; } while ($i>0); </programlisting> - </informalexample> - </para> - <simpara> + </informalexample> + </para> + <simpara> The above loop would run one time exactly, since after the first iteration, when truth expression is checked, it evaluates to <literal>FALSE</literal> ($i is not bigger than 0) and the loop execution ends. </simpara> - <para> + <para> Advanced C users may be familiar with a different usage of the <literal>do..while</literal> loop, to allow stopping execution in the middle of code blocks, by encapsulating them with - <literal>do..while</literal>(0), and using the <link - linkend="control-structures.break"><literal>break</literal></link> + <literal>do..while</literal>(0), and using the <link linkend="control-structures.break"> + <literal>break</literal> + </link> statement. The following code fragment demonstrates this: <informalexample> - <programlisting role="php"> + <programlisting role="php"> do { if ($i < 5) { print "i is not big enough"; @@ -320,59 +312,48 @@ } while(0); </programlisting> - </informalexample> - </para> - <simpara> + </informalexample> + </para> + <simpara> Don't worry if you don't understand this right away or at all. You can code scripts and even powerful scripts without using this `feature'. </simpara> - </sect1> - - <sect1 id="control-structures.for"> - <title><literal>for</literal></title> - <para> - <literal>for</literal> loops are the most complex loops in PHP. - They behave like their C counterparts. The syntax of a - <literal>for</literal> loop is: + </sect1> + <sect1 id="control-structures.for"> + <title> + <literal>for</literal> + </title> + <para> + <literal>for</literal> 루íë PHPìì ê°ì¥ ë³µì¡í 루íì´ë¤. + ì´ê²ì ííì Cì ë§¤ì° ì ì¬íë¤. <literal>for</literal> 루íì 문ë²ì ë¤ìê³¼ ê°ë¤. : <informalexample> - <programlisting> + <programlisting> for (expr1; expr2; expr3) statement </programlisting> - </informalexample> - </para> - <simpara> - The first expression (<replaceable>expr1</replaceable>) is - evaluated (executed) once unconditionally at the beginning of the - loop. - </simpara> - <simpara> - In the beginning of each iteration, - <replaceable>expr2</replaceable> is evaluated. If it evaluates to - <literal>TRUE</literal>, the loop continues and the nested - statement(s) are executed. If it evaluates to - <literal>FALSE</literal>, the execution of the loop ends. - </simpara> - <simpara> - At the end of each iteration, <replaceable>expr3</replaceable> is - evaluated (executed). - </simpara> - <simpara> - Each of the expressions can be empty. - <replaceable>expr2</replaceable> being empty means the loop should - be run indefinitely (PHP implicitly considers it as - <literal>TRUE</literal>, like C). This may not be as useless as - you might think, since often you'd want to end the loop using a - conditional <link - linkend="control-structures.break"><literal>break</literal></link> - statement instead of using the <literal>for</literal> truth - expression. + </informalexample> + </para> + <simpara> + 첫 ë²ì§¸ ííì(<replaceable>expr1</replaceable>)ì 루í를 ììí ë 무조건 íë² íê°(ì¤í)ëë¤. + </simpara> + <simpara> + 매 ë°ë³µì ìì ëë§ë¤ <replaceable>expr2</replaceable>ê° íê°ëë¤. + ë§ì½ ì´ê²ì´ <literal>TRUE</literal>ë©´ 루íë ê³ìëê³ statementê° ì¤íëë¤. + <literal>FALSE</literal>ì´ë©´ 루íë ì¢ ë£ëë¤. + </simpara> + <simpara> + 매 ë°ë³µì´ ëë ë <replaceable>expr3</replaceable>ê° íê°(ì¤í)ëë¤. + </simpara> + <simpara> + ê° íê°ìì ë¹ìë ì ìë¤. <replaceable>expr2</replaceable>ê° ë¹ì´ìì¼ë©´ 무í 루í를 ë»íë¤. + (PHPë Cì ê°ì´ ë¹ì´ìì¼ë©´ TRUEë¡ ì¸ìíë¤.) + ì´ê±´ ë³ë¡ ì¢ì ë°©ë²ì´ ìëì§ë§, ì¢ ì¢ ì´ë ê² ì¬ì©íê³ <link linkend="control-structures.break"> + <literal>break</literal></link>를 ì¬ì©íì¬ ì¢ ë£íë ë°©ë²ë ìë¤. </simpara> - <para> - Consider the following examples. All of them display numbers from - 1 to 10: + <para> + ë¤ì ìë 1ìì 10ê¹ì§ ì¶ë ¥íë ìì ë¤ì´ë¤. : <informalexample> - <programlisting role="php"> + <programlisting role="php"> /* example 1 */ for ($i = 1; $i <= 10; $i++) { @@ -403,86 +384,75 @@ for ($i = 1; $i <= 10; print $i, $i++) ; </programlisting> - </informalexample> - </para> - <simpara> - Of course, the first example appears to be the nicest one (or - perhaps the fourth), but you may find that being able to use empty - expressions in <literal>for</literal> loops comes in handy in many - occasions. - </simpara> - <para> - PHP also supports the alternate "colon syntax" for - <literal>for</literal> loops. + </informalexample> + </para> + <simpara> + ë¬¼ë¡ ì²ìê²ì´ ê°ì¥ ì¢ìë³´ì¸ë¤. ê·¸ë¬ë ë머ì§ë ê°ë¥íë¤ë ê²ì ììì¼ íë¤. + </simpara> + <para> + PHPë <literal>for</literal> 루íì ëí´ìë ë¤ìê³¼ ê°ì "colon syntax"를 ì§ìíë¤. <informalexample> - <programlisting> + <programlisting> for (expr1; expr2; expr3): statement; ...; endfor; </programlisting> - </informalexample> - </para> - <para> + </informalexample> + </para> + <para> Other languages have a <literal>foreach</literal> statement to traverse an array or hash. PHP 3 has no such construct; PHP 4 does - (see <link - linkend="control-structures.foreach">foreach</link>). In PHP 3, you + (see <link linkend="control-structures.foreach">foreach</link>). In PHP 3, you can combine <link linkend="control-structures.while">while</link> with the <function>list</function> and <function>each</function> functions to achieve the same effect. See the documentation for these functions for an example. </para> - - </sect1> - <sect1 id="control-structures.foreach"> - <title><literal>foreach</literal></title> - <para> - PHP 4 (not PHP 3) includes a <literal>foreach</literal> construct, - much like perl and some other languages. This simply gives an easy - way to iterate over arrays. There are two syntaxes; the second is - a minor but useful extension of the first: + </sect1> + <sect1 id="control-structures.foreach"> + <title> + <literal>foreach</literal> + </title> + <para> + PHP4(PHP3ë ìëë¤)ë perl ë±ì ë¤ë¥¸ ì¸ì´ê° ì ê³µíë foreach 구조를 ì ê³µíë¤. + ì´ êµ¬ì¡°ë ë°°ì´ì ìì´ì ë°ë³µì ì¸ ìì ì íëë° ì ì©íë¤. + ì´ê²ìë ëê°ì§ 문ë²ì´ ìëë°, ë ë²ì§¸ ê²ì 첫 ë²ì§¸ ê²ì ë¶ë¶ íì¥ì´ë¼ê³ + ìê°í ì ìì¼ë ì¤ì ë¡ ë§¤ì° ì ì©íê² ì¬ì©ëë¤. <informalexample> - <programlisting> + <programlisting> foreach(array_expression as $value) statement foreach(array_expression as $key => $value) statement </programlisting> - </informalexample> - </para> - <simpara> - The first form loops over the array given by - <literal>array_expression</literal>. On each loop, the value of - the current element is assigned to <literal>$value</literal> and - the internal array pointer is advanced by one (so on the next - loop, you'll be looking at the next element). - </simpara> - <simpara> - The second form does the same thing, except that the current - element's key will be assigned to the variable - <literal>$key</literal> on each loop. - </simpara> - <para> - <note> - <para> - When <literal>foreach</literal> first starts executing, the - internal array pointer is automatically reset to the first element - of the array. This means that you do not need to call - <function>reset</function> before a <literal>foreach</literal> - loop. + </informalexample> + </para> + <simpara> + 첫 ë²ì§¸ 모ìì <literal>array_expression</literal> ì¼ë¡ 주ì´ì§ ë°°ì´ì ëí´ ë£¨í를 ìííë¤. + ê°ê°ì 루íìì ë´ìì, ë°°ì´ì ììë <literal>$value</literal>ì ì ì¥ëê³ + ë´ë¶ ë°°ì´ í¬ì¸í°(internal array pointer)ë íë ì ì§íì¬ ë¤ì ìì ìì ìë¡ì´ ìì를 ê°ì ¸ì¤ëë¡ íë¤. + </simpara> + <simpara> + ë ë²ì§¸ 모ìì 첫 ë²ì§¸ì ëì¼í ìì ì íì§ë§, <literal>$key</literal>ì í´ë¹ ììì í¤ê°ì ì ì¥íê² ëë¤. + </simpara> + <para> + <note> + <para> + <literal>foreach</literal> ë¬¸ì´ ì²ì ìíë ë, ë´ë¶ ë°°ì´ í¬ì¸í°(internal array pointer)ë + ìëì ì¼ë¡ ë°°ì´ì 첫ë²ì§¸ ììë¡ ì¤ì ëë¤. ì´ë§ì ì미ë ì¬ë¬ë¶ì´ <literal>foreach</literal>문ì ì¬ì©í ë + <function>reset</function>ì 미리 í¸ì¶í íìë ìë¤ë ê²ì´ë¤. </para> - </note> - </para> - <para> - <note> - <para> + </note> + </para> + <para> + <note> + <para> Also note that <literal>foreach</literal> operates on a copy of the specified array, not the array itself, therefore the array pointer is not modified like with the each construct. </para> - </note> - </para> - <para> - You may have noticed that the following are functionally - identical: + </note> + </para> + <para> + ìëì ë ê°ì 문ì¥ì ëì¼í 결과를 ë§ë ë¤ë ê²ì ì ì ìì ê²ì´ë¤. : <informalexample> - <programlisting role="php"> + <programlisting role="php"> reset ($arr); while (list(, $value) = each ($arr)) { echo "Value: $value<br>\n"; @@ -492,10 +462,10 @@ echo "Value: $value<br>\n"; } </programlisting> - </informalexample> - The following are also functionally identical: + </informalexample> + ë¤ì ë ê°ì 문ì¥ë 기ë¥ì ì¼ë¡ ëì¼íë¤. : <informalexample> - <programlisting role="php"> + <programlisting role="php"> reset ($arr); while (list($key, $value) = each ($arr)) { echo "Key: $key; Value: $value<br>\n"; @@ -505,12 +475,12 @@ echo "Key: $key; Value: $value<br>\n"; } </programlisting> - </informalexample> - </para> - <para> - Some more examples to demonstrate usages: + </informalexample> + </para> + <para> + ì¶ê°ì ì¼ë¡ ëª ê°ì ìì 를 ë³´ì. : <informalexample> - <programlisting role="php"> + <programlisting role="php"> /* foreach example 1: value only */ $a = array (1, 2, 3, 17); @@ -542,25 +512,24 @@ print "\$a[$k] => $v.\n"; } </programlisting> - </informalexample> - </para> - </sect1> - - <sect1 id="control-structures.break"> - <title><literal>break</literal></title> - <simpara> - <literal>break</literal> ends execution of the current - <literal>for</literal>, <literal>while</literal>, or - <literal>switch</literal> structure. + </informalexample> + </para> + </sect1> + <sect1 id="control-structures.break"> + <title> + <literal>break</literal> + </title> + <simpara> + <literal>break</literal>ë <literal>for</literal>ë, <literal>while</literal>, <literal>switch</literal>ìì ë¹ ì ¸ ëê°ë ëª ë ¹ì´ë¤. </simpara> - <simpara> - <literal>break</literal> accepts an optional numeric argument + <simpara> + <literal>break</literal> accepts an optional numeric argument which tells it how many nested enclosing structures are to be broken out of. </simpara> - <para> - <informalexample> - <programlisting role="php"> + <para> + <informalexample> + <programlisting role="php"> $arr = array ('one', 'two', 'three', 'four', 'stop', 'five'); while (list (, $val) = each ($arr)) { if ($val == 'stop') { @@ -585,25 +554,26 @@ } } </programlisting> - </informalexample> - </para> - </sect1> - - <sect1 id="control-structures.continue"> - <title><literal>continue</literal></title> - <simpara> - <literal>continue</literal> is used within looping structures to + </informalexample> + </para> + </sect1> + <sect1 id="control-structures.continue"> + <title> + <literal>continue</literal> + </title> + <simpara> + <literal>continue</literal> is used within looping structures to skip the rest of the current loop iteration and continue execution at the beginning of the next iteration. </simpara> - <simpara> - <literal>continue</literal> accepts an optional numeric argument + <simpara> + <literal>continue</literal> accepts an optional numeric argument which tells it how many levels of enclosing loops it should skip to the end of. </simpara> - <para> - <informalexample> - <programlisting role="php"> + <para> + <informalexample> + <programlisting role="php"> while (list ($key, $value) = each ($arr)) { if (!($key % 2)) { // skip odd members continue; @@ -625,27 +595,28 @@ echo "Neither does this.<br>\n"; } </programlisting> - </informalexample> - </para> - </sect1> - - <sect1 id="control-structures.switch"> - <title><literal>switch</literal></title> - <simpara> + </informalexample> + </para> + </sect1> + <sect1 id="control-structures.switch"> + <title> + <literal>switch</literal> + </title> + <simpara> The <literal>switch</literal> statement is similar to a series of IF statements on the same expression. In many occasions, you may want to compare the same variable (or expression) with many different values, and execute a different piece of code depending on which value it equals to. This is exactly what the <literal>switch</literal> statement is for. - </simpara> - <para> + </simpara> + <para> The following two examples are two different ways to write the same thing, one using a series of <literal>if</literal> statements, and the other using the <literal>switch</literal> statement: <informalexample> - <programlisting role="php"> + <programlisting role="php"> if ($i == 0) { print "i equals 0"; } @@ -668,9 +639,9 @@ break; } </programlisting> - </informalexample> - </para> - <para> + </informalexample> + </para> + <para> It is important to understand how the <literal>switch</literal> statement is executed in order to avoid mistakes. The <literal>switch</literal> statement executes line by line @@ -685,7 +656,7 @@ statement list, PHP will go on executing the statements of the following case. For example: <informalexample> - <programlisting role="php"> + <programlisting role="php"> switch ($i) { case 0: print "i equals 0"; @@ -695,9 +666,9 @@ print "i equals 2"; } </programlisting> - </informalexample> - </para> - <simpara> + </informalexample> + </para> + <simpara> Here, if $i equals to 0, PHP would execute all of the print statements! If $i equals to 1, PHP would execute the last two print statements, and only if $i equals to 2, you'd get the @@ -706,7 +677,7 @@ (even though you may want to avoid supplying them on purpose under certain circumstances). </simpara> - <simpara> + <simpara> In a <literal>switch</literal> statement, the condition is evaluated only once and the result is compared to each <literal>case</literal> statement. In an <literal>elseif</literal> @@ -714,11 +685,11 @@ more complicated than a simple compare and/or is in a tight loop, a <literal>switch</literal> may be faster. </simpara> - <para> + <para> The statement list for a case can also be empty, which simply passes control into the statement list for the next case. <informalexample> - <programlisting role="php"> + <programlisting role="php"> switch ($i) { case 0: case 1: @@ -729,13 +700,13 @@ print "i is 3"; } </programlisting> - </informalexample> - </para> - <para> + </informalexample> + </para> + <para> A special case is the default case. This case matches anything that wasn't matched by the other cases. For example: <informalexample> - <programlisting role="php"> + <programlisting role="php"> switch ($i) { case 0: print "i equals 0"; @@ -750,21 +721,20 @@ print "i is not equal to 0, 1 or 2"; } </programlisting> - </informalexample> - </para> - <para> + </informalexample> + </para> + <para> The <literal>case</literal> expression may be any expression that evaluates to a simple type, that is, integer or floating-point numbers and strings. Arrays or objects cannot be used here unless they are dereferenced to a simple type. </para> - <para> + <para> The alternative syntax for control structures is supported with - switches. For more information, see <link - linkend="control-structures.alternative-syntax">Alternative syntax + switches. For more information, see <link linkend="control-structures.alternative-syntax">Alternative syntax for control structures</link> . <informalexample> - <programlisting role="php"> + <programlisting role="php"> switch ($i): case 0: print "i equals 0"; @@ -779,36 +749,36 @@ print "i is not equal to 0, 1 or 2"; endswitch; </programlisting> - </informalexample> - </para> - </sect1> - - <sect1 id="function.require"> - <title><function>require</function></title> - <simpara> + </informalexample> + </para> + </sect1> + <sect1 id="function.require"> + <title> + <function>require</function> + </title> + <simpara> The <function>require</function> statement replaces itself with the specified file, much like the C preprocessor's <literal>#include</literal> works. </simpara> - <simpara> + <simpara> If "URL fopen wrappers" are enabled in PHP (which they are in the default configuration), you can specify the file to be <function>require</function>ed using an URL instead of a local pathname. See <link linkend="features.remote-files">Remote files</link> and <function>fopen</function> for more information. </simpara> - <simpara> + <simpara> An important note about how this works is that when a file is <function>include</function>ed or <function>require</function>ed, parsing drops out of PHP mode and into HTML mode at the beginning of the target file, and resumes PHP mode again at the end. For this reason, any code inside the target file which should be - executed as PHP code must be enclosed within <link - linkend="language.basic-syntax.phpmode">valid PHP start and end + executed as PHP code must be enclosed within <link linkend="language.basic-syntax.phpmode">valid PHP start and end tags</link>. </simpara> - <simpara> - <function>require</function> is not actually a function in PHP; + <simpara> + <function>require</function> is not actually a function in PHP; rather, it is a language construct. It is subject to some different rules than functions are. For instance, <function>require</function> is not subject to any containing @@ -816,7 +786,7 @@ attempting to read a return value from a <function>require</function> call results in a parse error. </simpara> - <simpara> + <simpara> Unlike <function>include</function>, <function>require</function> will <emphasis>always</emphasis> read in the target file, <emphasis>even if the line it's on never executes</emphasis>. If @@ -826,24 +796,24 @@ which the <function>require</function> occurs is not executed, neither will any of the code in the target file be executed. </simpara> - <simpara> + <simpara> Similarly, looping structures do not affect the behaviour of <function>require</function>. Although the code contained in the target file is still subject to the loop, the <function>require</function> itself happens only once. </simpara> - <para> + <para> This means that you can't put a <function>require</function> statement inside of a loop structure and expect it to include the contents of a different file on each iteration. To do that, use an <function>include</function> statement. <informalexample> - <programlisting role="php"> + <programlisting role="php"> require ('header.inc'); </programlisting> - </informalexample> - </para> - <simpara> + </informalexample> + </para> + <simpara> When a file is <function>require</function>ed, the code it contains inherits the variable scope of the line on which the <function>require</function> occurs. Any variables available at @@ -853,7 +823,7 @@ in the called file will behave as though it had been defined inside that function. </simpara> - <para> + <para> If the <function>require</function>ed file is called via HTTP using the fopen wrappers, and if the target server interprets the target file as PHP code, variables may be passed to the @@ -864,7 +834,7 @@ on the remote server and the result is then being included into the local script. <informalexample> - <programlisting role="php"> + <programlisting role="php"> /* This example assumes that someserver is configured to parse .php * files and not .txt files. Also, 'works' here means that the variables * $varone and $vartwo are available within the require()ed file. */ @@ -884,9 +854,9 @@ require ("file.txt"); /* Works. */ require ("file.php"); /* Works. */ </programlisting> - </informalexample> - </para> - <simpara> + </informalexample> + </para> + <simpara> In PHP 3, it is possible to execute a <literal>return</literal> statement inside a <function>require</function>ed file, as long as that statement occurs in the global scope of the @@ -895,67 +865,66 @@ has been discontinued. If you need this functionality, see <function>include</function>. </simpara> - <simpara> + <simpara> See also <function>include</function>, <function>require_once</function>, <function>include_once</function>, <function>readfile</function>, and <function>virtual</function>. </simpara> - </sect1> - - <sect1 id="function.include"> - <title><function>include</function></title> - <simpara> + </sect1> + <sect1 id="function.include"> + <title> + <function>include</function> + </title> + <simpara> The <function>include</function> statement includes and evaluates the specified file. </simpara> - <simpara> + <simpara> If "URL fopen wrappers" are enabled in PHP (which they are in the default configuration), you can specify the file to be <function>include</function>ed using an URL instead of a local pathname. See <link linkend="features.remote-files">Remote files</link> and <function>fopen</function> for more information. </simpara> - <simpara> + <simpara> An important note about how this works is that when a file is <function>include</function>ed or <function>require</function>ed, parsing drops out of PHP mode and into HTML mode at the beginning of the target file, and resumes again at the end. For this reason, any code inside the target file which should be executed as PHP - code must be enclosed within <link - linkend="language.basic-syntax.phpmode">valid PHP start and end + code must be enclosed within <link linkend="language.basic-syntax.phpmode">valid PHP start and end tags</link>. </simpara> - <para> + <para> This happens each time the <function>include</function> statement is encountered, so you can use an <function>include</function> statement within a looping structure to include a number of different files. <informalexample> - <programlisting role="php"> + <programlisting role="php"> $files = array ('first.inc', 'second.inc', 'third.inc'); for ($i = 0; $i < count($files); $i++) { include $files[$i]; } </programlisting> - </informalexample> - </para> - <para> - <function>include</function> differs from + </informalexample> + </para> + <para> + <function>include</function> differs from <function>require</function> in that the include statement is re-evaluated each time it is encountered (and only when it is being executed), whereas the <function>require</function> statement is replaced by the required file when it is first encountered, whether the contents of the file will be evaluated or - not (for example, if it is inside an <link - linkend="control-structures.if">if</link> statement whose + not (for example, if it is inside an <link linkend="control-structures.if">if</link> statement whose condition evaluated to false). </para> - <para> + <para> Because <function>include</function> is a special language construct, you must enclose it within a statement block if it is inside a conditional block. <informalexample> - <programlisting role="php"> + <programlisting role="php"> /* This is WRONG and will not work as desired. */ if ($condition) @@ -971,9 +940,9 @@ include($other); } </programlisting> - </informalexample> - </para> - <simpara> + </informalexample> + </para> + <simpara> In both PHP 3 and PHP 4, it is possible to execute a <literal>return</literal> statement inside an <function>include</function>ed file, in order to terminate @@ -988,9 +957,10 @@ the <function>include</function> call as you would a normal function. This generates a parse error in PHP 3. </simpara> - <example> - <title><function>include</function> in PHP 3 and PHP 4</title> - <para> + <example> + <title> + <function>include</function> in PHP 3 and PHP 4</title> + <para> Assume the existence of the following file (named <filename>test.inc</filename>) in the same directory as the main file: @@ -1003,8 +973,8 @@ echo "After the return <br>\n"; ?> </programlisting> - </para> - <para> + </para> + <para> Assume that the main file (<filename>main.html</filename>) contains the following: <programlisting role="php"> @@ -1013,8 +983,8 @@ echo "File returned: '$retval'<br>\n"; ?> </programlisting> - </para> - <para> + </para> + <para> When <filename>main.html</filename> is called in PHP 3, it will generate a parse error on line 2; you can't take the value of an <function>include</function> in PHP 3. In PHP 4, however, the @@ -1023,8 +993,8 @@ Before the return File returned: '27' </screen> - </para> - <para> + </para> + <para> Now, assume that <filename>main.html</filename> has been altered to contain the following: <programlisting role="php"> @@ -1033,8 +1003,8 @@ echo "Back in main.html<br>\n"; ?> </programlisting> - </para> - <para> + </para> + <para> In PHP 4, the output will be: <screen> Before the return @@ -1047,8 +1017,8 @@ Parse error: parse error in /home/torben/public_html/phptest/main.html on line 5 </screen> - </para> - <para> + </para> + <para> The above parse error is a result of the fact that the <literal>return</literal> statement is enclosed in a non-function block within <filename>test.inc</filename>. When the return is @@ -1057,13 +1027,13 @@ Before the return 27Back in main.html </screen> - </para> - <para> + </para> + <para> The spurious '27' is due to the fact that PHP 3 does not support <literal>return</literal>ing values from files like that. </para> - </example> - <simpara> + </example> + <simpara> When a file is <function>include</function>ed, the code it contains inherits the variable scope of the line on which the <function>include</function> occurs. Any variables available at @@ -1073,7 +1043,7 @@ in the called file will behave as though it had been defined inside that function. </simpara> - <para> + <para> If the <function>include</function>ed file is called via HTTP using the fopen wrappers, and if the target server interprets the target file as PHP code, variables may be passed to the @@ -1084,7 +1054,7 @@ on the remote server and the result is then being included into the local script. <informalexample> - <programlisting role="php"> + <programlisting role="php"> /* This example assumes that someserver is configured to parse .php * files and not .txt files. Also, 'works' here means that the variables * $varone and $vartwo are available within the include()ed file. */ @@ -1104,18 +1074,19 @@ include ("file.txt"); /* Works. */ include ("file.php"); /* Works. */ </programlisting> - </informalexample> - </para> - <simpara> + </informalexample> + </para> + <simpara> See also <function>require</function>, <function>require_once</function>, <function>include_once</function>, <function>readfile</function>, and <function>virtual</function>. </simpara> - </sect1> - - <sect1 id="function.require-once"> - <title><function>require_once</function></title> - <para> + </sect1> + <sect1 id="function.require-once"> + <title> + <function>require_once</function> + </title> + <para> The <function>require_once</function> statement replaces itself with the specified file, much like the C preprocessor's <literal>#include</literal> works, and in that respect is @@ -1125,12 +1096,12 @@ added to your script only once, and avoid clashes with variable values or function names that can happen. </para> - <para> + <para> For example, if you create the following 2 include files <literal>utils.inc</literal> and <literal>foolib.inc</literal> - <example> - <title>utils.inc</title> - <programlisting role="php"> + <example> + <title>utils.inc</title> + <programlisting role="php"> <?php define(PHPVERSION, floor(phpversion())); echo "GLOBALS ARE NICE\n"; @@ -1139,10 +1110,10 @@ } ?> </programlisting> - </example> - <example> - <title>foolib.inc</title> - <programlisting role="php"> + </example> + <example> + <title>foolib.inc</title> + <programlisting role="php"> <?php require ("utils.inc"); function showVar($var) { @@ -1156,11 +1127,11 @@ // bunch of other functions ... ?> </programlisting> - </example> + </example> And then you write a script <literal>cause_error_require.php</literal> - <example> - <title>cause_error_require.php</title> - <programlisting role="php"> + <example> + <title>cause_error_require.php</title> + <programlisting role="php"> <?php require("foolib.inc"); /* the following will generate an error */ @@ -1173,44 +1144,44 @@ showVar($foo); ?> </programlisting> - </example> + </example> When you try running the latter one, the resulting ouptut will be (using PHP 4.01pl2): <informalexample> - <programlisting> + <programlisting> GLOBALS ARE NICE GLOBALS ARE NICE Fatal error: Cannot redeclare goodTea() in utils.inc on line 5 </programlisting> - </informalexample> + </informalexample> By modifying <literal>foolib.inc</literal> and <literal>cause_errror_require.php</literal> to use <function>require_once</function> instead of <function>require</function> and renaming the last one to <literal>avoid_error_require_once.php</literal>, we have: <example> - <title>foolib.inc (fixed)</title> - <programlisting role="php"> + <title>foolib.inc (fixed)</title> + <programlisting role="php"> ... require_once("utils.inc"); function showVar($var) { ... </programlisting> - </example> - <example> - <title>avoid_error_require_once.php</title> - <programlisting role="php"> + </example> + <example> + <title>avoid_error_require_once.php</title> + <programlisting role="php"> ... require_once("foolib.inc"); require_once("utils.inc"); $foo = array("1",array("complex","quaternion")); ... </programlisting> - </example> + </example> And when running the latter, the output will be (using PHP 4.0.1pl2): <informalexample> - <programlisting> + <programlisting> GLOBALS ARE NICE this is requiring globals.inc again which is also required in foolib.inc @@ -1227,9 +1198,9 @@ ) </programlisting> - </informalexample> - </para> - <para> + </informalexample> + </para> + <para> Also note that, analogous to the behavior of the <literal>#include</literal> of the C preprocessor, this statement acts at "compile time", e.g. when the script is parsed and before it @@ -1238,30 +1209,31 @@ <function>include_once</function> or <function>include</function> for that purpose. </para> - <para> + <para> For more examples on using <function>require_once</function> and <function>include_once</function>, look at the PEAR code included in the latest PHP source code distributions. </para> - <para> + <para> See also: <function>require</function>, <function>include</function>, <function>include_once</function>, <function>get_required_files</function>, <function>get_included_files</function>, <function>readfile</function>, and <function>virtual</function>. </para> - </sect1> - - <sect1 id="function.include-once"> - <title><function>include_once</function></title> - <para> + </sect1> + <sect1 id="function.include-once"> + <title> + <function>include_once</function> + </title> + <para> The <function>include_once</function> statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the <function>include</function> statement, with the important difference that if the code from a file has already been included, it will not be included again. </para> - <para> + <para> As mentioned in the <function>require_once</function> description, the <function>include_once</function> should be used in the cases in which the same file might be included and evaluated more than once during a @@ -1269,26 +1241,24 @@ included exactly once to avoid problems with function redefinitions, variable value reassignments, etc. </para> - <para> + <para> For more examples on using <function>require_once</function> and <function>include_once</function>, look at the PEAR code included in the latest PHP source code distributions. </para> - <para> - <function>include_once</function> was added in PHP 4.0.1pl2 + <para> + <function>include_once</function> was added in PHP 4.0.1pl2 </para> - <para> + <para> See also: <function>require</function>, <function>include</function>, <function>require_once</function>, <function>get_required_files</function>, <function>get_included_files</function>, <function>readfile</function>, and <function>virtual</function>. </para> - </sect1> - - </chapter> - - <!-- Keep this comment at the end of the file + </sect1> +</chapter> +<!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t Index: phpdoc/kr/language/expressions.xml diff -u phpdoc/kr/language/expressions.xml:1.2 phpdoc/kr/language/expressions.xml:1.3 --- phpdoc/kr/language/expressions.xml:1.2 Tue Jan 9 16:41:17 2001 +++ phpdoc/kr/language/expressions.xml Wed Jan 10 02:54:00 2001 @@ -1,38 +1,28 @@ - <chapter id="language.expressions"> - <title>Expressions</title> - - <simpara> - Expressions are the most important building stones of PHP. In PHP, - almost anything you write is an expression. The simplest yet - most accurate way to define an expression is "anything that has a - value".</simpara> - - <simpara> - The most basic forms of expressions are constants and variables. - When you type "$a = 5", you're assigning '5' into $a. '5', obviously, - has the value 5, or in other words '5' is an expression with the - value of 5 (in this case, '5' is an integer constant).</simpara> - - <simpara> - After this assignment, you'd expect $a's value to be 5 as - well, so if you wrote $b = $a, you'd expect it to behave just as - if you wrote $b = 5. In other words, $a is an expression with the - value of 5 as well. If everything works right, this is exactly - what will happen.</simpara> - - <para> - Slightly more complex examples for expressions are functions. For - instance, consider the following function: - +<chapter id="language.expressions"> + <title>ííì (Expressions)</title> + <simpara> + ííìì PHPìì ë§¤ì° ì¤ìí ë´ì©ì´ë¤. + PHPìì ì¬ë¬ë¶ì´ ìì±íë ê±°ì 모ë ê²ì ííìì´ë¤. + ê°ë¨í ííìì ì ì를 ìë°íê² ë§íë¤ë©´ "ê°ì ê°ì§ê³ ìë 모ë ê²"("anything that has a value")ì´ë¤. + </simpara> + <simpara> + ê°ë¨í ìì ë¡ "$a = 5"ì ê°ì ê²ì´ ìë¤. ì´ê²ì '5'ë¼ë ê°ì $aë¼ë ë³ìì ëì íë 문ì¥ì´ë¤. + ì¬ê¸°ì '5'ë¼ë ííìì ê° 5 ë¼ë ìë¯¸ê° ëë¤. + </simpara> + <simpara> + ìì ë¬¸ì¥ ë¤ìì "$b = $a"ë¼ë 문ì¥ì´ ìë¤ë©´, ì¬ê¸°ì $aë¼ë ííìì ê·¸ ë³ìê° ê°ì§ 5ë¼ë ê°ì íííë¤. + </simpara> + <para> + ì¡°ê¸ ë³µì¡í ê²½ì°ë í¨ìì´ë¤. ë¤ì í¨ì를 ë³´ì. : <informalexample> - <programlisting> + <programlisting> function foo () { return 5; } </programlisting> - </informalexample></para> - - <simpara> + </informalexample> + </para> + <simpara> Assuming you're familiar with the concept of functions (if you're not, take a look at the chapter about functions), you'd assume that typing <literal>$c = foo()</literal> is essentially just like @@ -40,8 +30,7 @@ are expressions with the value of their return value. Since foo() returns 5, the value of the expression 'foo()' is 5. Usually functions don't just return a static value but compute something.</simpara> - - <simpara> + <simpara> Of course, values in PHP don't have to be integers, and very often they aren't. PHP supports three scalar value types: integer values, floating point values and string values (scalar values are values that @@ -49,8 +38,7 @@ PHP also supports two composite (non-scalar) types: arrays and objects. Each of these value types can be assigned into variables or returned from functions.</simpara> - - <simpara> + <simpara> So far, users of PHP/FI 2 shouldn't feel any change. However, PHP takes expressions much further, in the same way many other languages do. PHP is an expression-oriented language, in the @@ -66,8 +54,7 @@ '$b = ($a = 5)' is like writing '$a = 5; $b = 5;' (a semicolon marks the end of a statement). Since assignments are parsed in a right to left order, you can also write '$b = $a = 5'.</simpara> - - <simpara> + <simpara> Another good example of expression orientation is pre- and post-increment and decrement. Users of PHP/FI 2 and many other languages may be familiar with the notation of variable++ and @@ -86,8 +73,7 @@ written '$variable++' evaluates to the original value of $variable, before it was incremented (PHP increments the variable after reading its value, thus the name 'post-increment').</simpara> - - <simpara> + <simpara> A very common type of expressions are comparison expressions. These expressions evaluate to either 0 or 1, meaning FALSE or TRUE (respectively). PHP supports > (bigger than), >= (bigger than @@ -95,8 +81,7 @@ (smaller than or equal to). These expressions are most commonly used inside conditional execution, such as <literal>if</literal> statements.</simpara> - - <simpara> + <simpara> The last example of expressions we'll deal with here is combined operator-assignment expressions. You already know that if you want to increment $a by 1, you can simply write '$a++' or '++$a'. @@ -117,26 +102,26 @@ assigned into $a). Any two-place operator can be used in this operator-assignment mode, for example '$a -= 5' (subtract 5 from the value of $a), '$b *= 7' (multiply the value of $b by 7), etc.</simpara> - - <para> + <para> There is one more expression that may seem odd if you haven't seen it in other languages, the ternary conditional operator: - <informalexample><programlisting> + <informalexample> + <programlisting> $first ? $second : $third -</programlisting></informalexample> +</programlisting> + </informalexample> If the value of the first subexpression is true (non-zero), then it the second subexpression is evaluated, and that is the result of the conditional expression. Otherwise, the third subexpression is evaluated, and that is the value.</para> - - <para> + <para> The following example should help you understand pre- and post-increment and expressions in general a bit better: <informalexample> - <programlisting> + <programlisting> function double($i) { return $i*2; } @@ -156,9 +141,10 @@ value of 24. the value of the assignment (24) is then assigned into $h, and $h ends with the value of 24 as well. */ -</programlisting></informalexample></para> - - <simpara> +</programlisting> + </informalexample> + </para> + <simpara> In the beginning of the chapter we said that we'll be describing the various statement types, and as promised, expressions can be statements. However, not every expression is a statement. In @@ -166,8 +152,7 @@ expression followed by a semicolon. In '$b=$a=5;', $a=5 is a valid expression, but it's not a statement by itself. '$b=$a=5;' however is a valid statement.</simpara> - - <simpara> + <simpara> One last thing worth mentioning is the truth value of expressions. In many events, mainly in conditional execution and loops, you're not interested in the specific value of the expression, but only @@ -180,18 +165,15 @@ With non-scalar values (arrays and objects) - if the value contains no elements it's considered FALSE, otherwise it's considered TRUE.</simpara> - - <simpara> + <simpara> PHP provides a full and powerful implementation of expressions, and documenting it entirely goes beyond the scope of this manual. The above examples should give you a good idea about what expressions are and how you can construct useful expressions. Throughout the rest of this manual we'll write <replaceable>expr</replaceable> to indicate any valid PHP expression.</simpara> - - </chapter> - - <!-- Keep this comment at the end of the file +</chapter> +<!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t