cvs: phpdoc-zh /language expressions.xml
| From: | Shaolei Mu | Date: | Thu, 18 Jul 2002 15:04:24 +0000 |
| Subject: | cvs: phpdoc-zh /language expressions.xml | ||
| Groups: | php.doc.zh | ||
| Request: | Send a blank email to doc-zh+get-143@lists.php.net to get a copy of this message | ||
verdana Thu Jul 18 11:04:24 2002 EDT
Modified files:
/phpdoc-zh/language expressions.xml
Log:
complete translation
Index: phpdoc-zh/language/expressions.xml diff -u phpdoc-zh/language/expressions.xml:1.1 phpdoc-zh/language/expressions.xml:1.2 --- phpdoc-zh/language/expressions.xml:1.1 Sun Jul 14 11:31:09 2002 +++ phpdoc-zh/language/expressions.xml Thu Jul 18 11:04:23 2002 @@ -1,5 +1,7 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> +<!-- $AUTHOR$ --> +<!-- EN-Revision: 1.19 Maintainer: verdana Status: ready --> <chapter id="language.expressions"> <title>±í´ïʽ</title> @@ -43,86 +45,59 @@ </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 - you can't 'break' into smaller pieces, unlike arrays, for instance). - 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> - 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 - sense that almost everything is an expression. Consider the - example we've already dealt with, '$a = 5'. It's easy to see that - there are two values involved here, the value of the integer - constant '5', and the value of $a which is being updated to 5 as - well. But the truth is that there's one additional value involved - here, and that's the value of the assignment itself. The - assignment itself evaluates to the assigned value, in this case 5. - In practice, it means that '$a = 5', regardless of what it does, - is an expression with the value 5. Thus, writing something like - '$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> - 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 - variable--. These are increment and decrement operators. In - PHP/FI 2, the statement '$a++' has no value (is not an - expression), and thus you can't assign it or use it in any way. - PHP enhances the increment/decrement capabilities by making - these expressions as well, like in C. In PHP, like in C, there - are two types of increment - pre-increment and post-increment. - Both pre-increment and post-increment essentially increment the - variable, and the effect on the variable is idential. The - difference is with the value of the increment expression. - Pre-increment, which is written '++$variable', evaluates to the - incremented value (PHP increments the variable before reading its - value, thus the name 'pre-increment'). Post-increment, which is - 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> - 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 - or equal to), == (equal), != (not equal), < (smaller than) and <= - (smaller than or equal to). These expressions are most commonly used - inside conditional execution, such as <literal>if</literal> - statements.</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'. - But what if you want to add more than one to it, for instance 3? - You could write '$a++' multiple times, but this is obviously not a - very efficient or comfortable way. A much more common practice is - to write '$a = $a + 3'. '$a + 3' evaluates to the value of $a - plus 3, and is assigned back into $a, which results in - incrementing $a by 3. In PHP, as in several other languages - like C, you can write this in a shorter way, which with time would - become clearer and quicker to understand as well. Adding 3 to the - current value of $a can be written '$a += 3'. This means exactly - "take the value of $a, add 3 to it, and assign it back into $a". - In addition to being shorter and clearer, this also results in - faster execution. The value of '$a += 3', like the value of a - regular assignment, is the assigned value. Notice that it is NOT - 3, but the combined value of $a plus 3 (this is the value that's - 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> + µ±È»£¬PHP ÖеÄÖµ³£³£²¢·ÇÊÇÕûÐ͵ġ£PHP Ö§³ÖÈýÖÖ±êÁ¿ÖµÀàÐÍ£ºÕûÐÍÖµ£¬¸¡µãÖµºÍ×Ö·û´®Öµ + £¨±êÁ¿Öµ²»Äܲð·ÖΪ¸üСµÄµ¥Ôª£¬±ÈÈ磺Êý×飩¡£PHP Ò²Ö§³ÖÁ½ÖÖ¸´ºÏÀàÐÍ£ºÊý×éºÍ¶ÔÏó¡£ + ÕâÁ½ÖÖÀàÐ;߿ÉÒÔ¸³Öµ¸ø±äÁ¿»òÕß´Óº¯Êý·µ»Ø¡£</simpara> + + <simpara> + µ½Ä¿Ç°ÎªÖ¹£¬PHP/FI 2 µÄÓû§²»Ó¦¸Ã¸Ðµ½Èκεı仯¡£È»¶ø£¬µ±Ðí¶àÆäËüÓïÑÔ + Ϊ֮ŬÁ¦µÄʱºò£¬PHP ÔÚÏàͬµÀ·ÉÏ´Ù½øÁ˱í´ïʽµÄ³É³¤¡£PHP ÊÇÒ»ÖÖÃæÏò±í´ïʽ + µÄÓïÑÔ£¬´ÓÕâÒ»·½ÃæÀ´½²¼¸ºõÒ»Çж¼ÊDZí´ïʽ¡£¿¼ÂǸղÅÎÒÃÇÒѾÑо¿¹ýµÄÀý×Ó£¬ + ¡®$a = 5¡¯¡£¿ÉÒÔÇáËɵĿ´µ½ÕâÀïÓÐÁ½¸öÏà¹ØµÄÖµ£¬ÕûÐͳ£Á¿ '5'£¬¶øÇÒ±äÁ¿ $a + µÄÖµÒ²±»¸üÐÂΪ5¡£µ«ÊÇÊÂʵÊÇ£ºÕâÀïÖ»ÓÐÒ»¸öÏà¹ØµÄ¸½¼ÓÖµ£¬¼´±»·ÖÅäµÄÖµ±¾Éí¡£ + ¸³Öµ²Ù×÷¼ÆËãÐè·ÖÅäµÄÖµ£¬¼´5¡£Êµ¼ÊÉÏ£¬Òâζ×Å¡®$a = 5¡¯£¬²»±Ø¹ÜËüÊÇ×öʲôµÄ£¬ + ÊÇÒ»¸öֵΪ5µÄ±í´ïʽ¡£Òò¶ø£¬Ò»Ð©ÏñÕâÑùµÄ´úÂë¡®$b = ($a = 5)¡¯ºÍ¡®$a =5; $b=5¡¯ + £¨·ÖºÅ±êÖ¾×ÅÓï¾äµÄ½áÊø£©¡£ÒòΪ¸³Öµ²Ù×÷µÄ˳ÐòÊÇÓÉÓÒµ½×óµÄ£¬ÄãÒ²¿ÉÒÔÕâôд + ¡®$b = $a =5¡¯¡£</simpara> + + <simpara> + ÁíÍâÒ»¸öºÜºÃµÄÃæÏò±í´ïʽµÄÀý×Ó¾ÍÊÇǰ¡¢ºóµÝÔöºÍµÝ¼õ¡£ + PHP/FI 2 ºÍ¶àÊýÆäËüÓïÑÔµÄÓû§Ó¦¸Ã±È½ÏÊìϤ±äÁ¿++ºÍ±äÁ¿--·ûºÅ¡£¼´µÝÔöºÍµÝ¼õ + ²Ù×÷·û¡£ÔÚ PHP/FI 2 ÖУ¬Óï¾ä¡®$a++¡¯Ã»ÓÐÖµ£¨²»ÊDZí´ïʽ£©£¬ÕâÑùµÄ»°Äã±ã²»ÄÜΪ + Æä¸³Öµ»òÕßÒÔÈÎºÎÆäËü·½Ê½À´Ê¹ÓÃËü¡£PHP ͨ¹ý½«Æä±äΪÁ˱í´ïʽ£¬Èç C ÓïÑÔ£¬ÔöÇ¿ÁË + µÝÔö/µÝ¼õµÄÄÜÁ¦¡£ÔÚ PHP ºÍ C ÓïÑÔ ÖУ¬ÓÐÁ½ÖÖÀàÐ͵ĵÝÔöǰµÝÔöºÍºóµÝÔö£¬±¾ÖÊ + ÉÏÀ´½²£¬Ç°µÝÔöºÍºóµÝÔö¾ùÔö¼ÓÁ˱äÁ¿µÄÖµ£¬²¢ÇÒ¶ÔÓÚ±äÁ¿µÄÓ°ÏìÊÇÏàͬµÄ¡£²»Í¬µÄÊÇ + µÝÔö±í´ïʽµÄÖµ¡£Ç°µÝÔö£¬Ð´×ö¡®++$variable¡¯£¬ÇóÔö¼ÓºóµÄÖµ£¨PHP ÔÚ¶ÁÈ¡±äÁ¿µÄÖµ + ֮ǰ£¬Ôö¼Ó±äÁ¿µÄÖµ£¬Òò¶ø³ÆÖ®Îª¡®Ç°µÝÔö¡¯£©¡£ºóµÝÔö£¬Ð´×ö¡®$variable++¡¯£¬Çó±äÁ¿ + δµÝÔö֮ǰµÄÔʼֵ£¨PHP ÔÚ¶ÁÈ¡±äÁ¿µÄÖµÖ®ºó£¬Ôö¼Ó±äÁ¿µÄÖµ£¬Òò¶ø½Ð×ö¡®ºóµÝÔö¡¯£©¡£ + ¡¾ÒëÕß×¢:ǰµÝÔö£¬++$a, Ôò¸Ã±í´ïʽµÄÖµ¼Ó1£»ºóµÝÔö, $a++, Ôò¸Ã±í´ïʽµÄÖµ²»±ä¡£¡¿ + </simpara> + + <simpara> + Ò»¸ö³£Óõ½±í´ïʽÀàÐÍÊDZȽϱí´ïʽ¡£ÕâЩ±í´ïʽÇóÖµ0»òÕß1£¬¼´ &false; »òÕß &true; + (·Ö±ðµÄ)¡£PHP Ö§³Ö >£¨´óÓÚ£©£¬>=£¨´óÓÚµÈÓÚ£©£¬ + ==£¨µÈÓÚ£©£¬!=£¨²»µÈÓÚ£©£¬<£¨Ð¡ÓÚ£©£¬<= (СÓÚµÈÓÚ)¡£ÕâЩ±í´ïʽ + ¶¼ÊÇÔÚÌõ¼þÅжÏÓï¾ä£¬±ÈÈ磬<literal>if</literal>Óï¾äÖÐ×î³£Óõġ£ + </simpara> + + <simpara> + ÕâÀÎÒÃǽ«ÒªÑо¿µÄ×îºóÒ»¸öÀý×ÓÊÇ×éºÏµÄ¸³Öµ²Ù×÷·û±í´ïʽ¡£ÄãÒѾ֪µÀÈç¹û + ÏëҪΪ±äÁ¿ $a ¼Ó1£¬¿ÉÒÔ¼òµ¥µÄд¡®$a++¡¯»òÕß¡®++$a¡¯¡£µ«ÊÇÈç¹ûÄãÏëΪ±äÁ¿Ôö¼Ó + ´óÓÚ1µÄÖµ£¬±ÈÈç3£¬¸ÃÔõô×ö£¿Äã¿ÉÒÔ¶à´Îд¡®$a++¡¯£¬µ«ÕâÑùÃ÷ÏÔ²»ÊÇÒ»ÖÖ + ¸ßÐ§ÊæÊʵķ½·¨£¬Ò»¸ö¸ü¼ÓͨÓõÄ×ö·¨ÊÇ¡®$a = $a + 3¡¯¡£¡®$a + 3¡¯ ¼ÆËã $a ¼ÓÉÏ3 + µÄÖµ£¬²¢Çҵõ½µÄÖµÖØÐ¸³Óè±äÁ¿ $a, ÓÚÊÇ $a µÄÖµÔö¼ÓÁË3¡£ÔÚ PHP ¼°ÆäËü + ¼¸ÖÖÀàËÆ C µÄÓïÑÔÖУ¬Äã¿ÉÒÔÒÔÒ»ÖÖ¸ü¼Ó¼ò¶ÌµÄÐÎʽÍê³ÉÉÏÊö¹¦ÄÜ£¬Òò¶øÒ²¸ü¼ÓÇå³þ¿ì½Ý¡£ + Ϊ $a µÄµ±Ç°Öµ¼Ó3£¬¿ÉÒÔÕâÑùд£º$a += 3¡£ÕâÀïµÄÒâ˼ÊÇ¡°È¡±äÁ¿ $a µÄÖµ£¬¼Ó3£¬ + µÃµ½µÄ½á¹ûÔٴηÖÅ䏸±äÁ¿ $a¡±¡£³ýÁ˸ü¼òÂÔºÍÇå³þÍ⣬Ҳ¿ÉÒÔ¸ü¿ìµÄÔËÐС£ + ¡®$a += 3¡¯µÄÖµ£¬Èçͬһ¸öÕý³£¸³Öµ²Ù×÷µÄÖµ£¬ÊǸ³ÖµºóµÄÖµ¡£×¢ÒâËü²»ÊÇ3£¬¶øÊÇ + $a ¼ÓÉÏ3µÄ×éºÏÖµ£¨¼´ÒѾ·ÖÅ䏸 $a µÄÖµ£©¡¾ÒëÕß×¢£ºÕâÀï±í´ïʽ¡®$a += 3¡¯µÄÖµÊÇÊ²Ã´ÄØ£¿ + ²»ÊÇ3£¬Ò²²»ÊÇ $a µÄÔʼֵ£¬¶øÊÇÍê³É +3 ²Ù×÷ºó±äÁ¿ $a µÄÖµ¡¿¡£ + ÈκÎÁ½Î»²Ù×÷·û¶¼¿ÉÒÔʹÓÃÔÚ¸´ÖƲÙ×÷·ûģʽ£¬ÀýÈç¡®$a -= 5¡¯£¨´Ó±äÁ¿ $a µÄÖµÖмõÈ¥5£©£¬ + ¡®$b *= 7¡¯ £¨±äÁ¿ $b ³ËÒÔ 7£©£¬µÈµÈ¡£ </simpara> <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> <![CDATA[ @@ -130,15 +105,12 @@ ]]> </programlisting></informalexample> - If the value of the first subexpression is &true; (non-zero), then - 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. + Èç¹ûµÚÒ»¸ö×Ó±í´ïʽµÄÖµÊÇ &true; £¨·ÇÁ㣩£¬ÄÇô¼ÆËãµÚ¶þ¸ö×Ó±í´ïʽµÄÖµ£¬ + ÆäÖµ¼´ÎªÕû¸ö±í´ïʽµÄÖµ¡£·ñÔò£¬½«ÊǵÚÈý¸ö×Ó±í´ïʽµÄÖµ¡£ </para> <para> - The following example should help you understand pre- and - post-increment and expressions in general a bit better: + ÏÂÃæµÄÀý×ÓÒ»°ãÀ´ËµÓ¦¸Ã¿ÉÒÔÉÔ΢°ïÄãÀí½âǰ¡¢ºóµÝÔöºÍ±í´ïʽ£º <informalexample> <programlisting role="php"> @@ -169,36 +141,31 @@ </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 - this case, a statement has the form of 'expr' ';' that is, an - 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> + ÔÚ±¾ÕµĿªÊ¼£¬ÎÒÃÇ˵¹ýÎÒÃǽ«»áÃèÊö¶àÖÖÓï¾äÀàÐÍ£¬²¢ÇÒÈçͬÐíŵµÄÄÇÑù£¬ + ±í´ïʽ¿ÉÒÔÊÇÓï¾ä¡£¾¡¹ÜÈç´Ë£¬²»ÊÇÿ¸ö±í´ïʽ¶¼ÊÇÒ»¸öÓï¾ä¡£¶øÕâÑùµÄ»°£¬ + Ò»¸öÓï¾ä£¬ËüµÄÐÎʽÊÇ'expr' ';'£¬Ò»¸ö±í´ïʽÓÐÒ»¸ö·ÖºÅ½áβ¡£ÔÚ¡®$b=$a=5;¡¯£¬ + $a=5 ÊÇÒ»¸öÓÐЧµÄ±í´ïʽ£¬µ«ÊÇËüÈ´²»ÊÇÒ»¸öÓï¾ä¡£¡®$b=$a=5;¡¯ È´ÊÇÒ»¸öÓÐЧ + µÄÓï¾ä¡£ + </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 - care about whether it means &true; or &false;. - + ×îºóÒ»¼þÖµµÃÌáÆðµÄÊÂÇé¾ÍÊDZí´ïʽµÄÕæÊµÖµ¡£ÔÚÐí¶àʼþÖУ¬´óÌåÉÏÖ÷ÒªÊÇ + ÔÚÌõ¼þÖ´ÐкÍÑ»·ÖУ¬²»Òª×¨×¢ÓÚ±í´ïʽÖÐÃ÷È·µÄÖµ£¬·´¶øÒª×¢Òâ±í´ïʽµÄ + ÖµÊÇ·ñÊÇ &true; »òÕß &false;¡£ + <!-- (PHP doesn't have a dedicated boolean type) : WRONG, php does. --> - - The constants &true; and &false; (case-insensitive) are the two - possible boolean values. When necessary, an expression is - automatically converted to boolean. See the - <link linkend="language.types.typecasting">section about - type-casting</link> for details about how. + + ³£Á¿ &true; ºÍ &false; £¨´óСдÎ޹أ©ÊÇÁ½ÖÖ¿ÉÄÜµÄ Boolean Öµ¡£Èç¹ûÓÐ + ±ØÒª£¬Ò»¸ö±í´ïʽ½«×Ô¶¯×ª»»Îª Boolean¡£²ÎÕÕ + <link linkend="language.types.typecasting">¹ØÓÚÀàÐÍÌø×ªµÄ²¿·Ö</link>¡£ </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> + PHP ÌṩÁËÒ»Ì×ÍêÕûÇ¿´óµÄ±í´ïʽ£¬¶øÎªËüÌṩÍêÕûµÄÎļþ×ÊÁÏÒѾ³¬³öÁË + ±¾ÊÖ²áµÄ·¶Î§¡£ÉÏÃæµÄÀý×ÓÓ¦¸ÃΪÄãÌṩÁËÒ»¸öºÃµÄ¹ØÓÚʲôÊDZí´ïʽºÍÔõ + Ñù¹¹½¨Ò»¸öÓÐÓõıí´ïʽµÄ¸ÅÄî¡£ÔÚ±¾ÊÖ²áµÄÆäÓಿ·Ö£¬ÎÒÃǽ«Ê¼ÖÕʹÓà + <replaceable>expr</replaceable>À´±íʾһ¸öÓÐЧµÄ PHP ±í´ïʽ¡£ + </simpara> </chapter>
Index: phpdoc-zh/language/expressions.xml diff -u phpdoc-zh/language/expressions.xml:1.1 phpdoc-zh/language/expressions.xml:1.2 --- phpdoc-zh/language/expressions.xml:1.1 Sun Jul 14 11:31:09 2002 +++ phpdoc-zh/language/expressions.xml Thu Jul 18 11:04:23 2002 @@ -1,5 +1,7 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> +<!-- $AUTHOR$ --> +<!-- EN-Revision: 1.19 Maintainer: verdana Status: ready --> <chapter id="language.expressions"> <title>±í´ïʽ</title> @@ -43,86 +45,59 @@ </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 - you can't 'break' into smaller pieces, unlike arrays, for instance). - 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> - 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 - sense that almost everything is an expression. Consider the - example we've already dealt with, '$a = 5'. It's easy to see that - there are two values involved here, the value of the integer - constant '5', and the value of $a which is being updated to 5 as - well. But the truth is that there's one additional value involved - here, and that's the value of the assignment itself. The - assignment itself evaluates to the assigned value, in this case 5. - In practice, it means that '$a = 5', regardless of what it does, - is an expression with the value 5. Thus, writing something like - '$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> - 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 - variable--. These are increment and decrement operators. In - PHP/FI 2, the statement '$a++' has no value (is not an - expression), and thus you can't assign it or use it in any way. - PHP enhances the increment/decrement capabilities by making - these expressions as well, like in C. In PHP, like in C, there - are two types of increment - pre-increment and post-increment. - Both pre-increment and post-increment essentially increment the - variable, and the effect on the variable is idential. The - difference is with the value of the increment expression. - Pre-increment, which is written '++$variable', evaluates to the - incremented value (PHP increments the variable before reading its - value, thus the name 'pre-increment'). Post-increment, which is - 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> - 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 - or equal to), == (equal), != (not equal), < (smaller than) and <= - (smaller than or equal to). These expressions are most commonly used - inside conditional execution, such as <literal>if</literal> - statements.</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'. - But what if you want to add more than one to it, for instance 3? - You could write '$a++' multiple times, but this is obviously not a - very efficient or comfortable way. A much more common practice is - to write '$a = $a + 3'. '$a + 3' evaluates to the value of $a - plus 3, and is assigned back into $a, which results in - incrementing $a by 3. In PHP, as in several other languages - like C, you can write this in a shorter way, which with time would - become clearer and quicker to understand as well. Adding 3 to the - current value of $a can be written '$a += 3'. This means exactly - "take the value of $a, add 3 to it, and assign it back into $a". - In addition to being shorter and clearer, this also results in - faster execution. The value of '$a += 3', like the value of a - regular assignment, is the assigned value. Notice that it is NOT - 3, but the combined value of $a plus 3 (this is the value that's - 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> + µ±È»£¬PHP ÖеÄÖµ³£³£²¢·ÇÊÇÕûÐ͵ġ£PHP Ö§³ÖÈýÖÖ±êÁ¿ÖµÀàÐÍ£ºÕûÐÍÖµ£¬¸¡µãÖµºÍ×Ö·û´®Öµ + £¨±êÁ¿Öµ²»Äܲð·ÖΪ¸üСµÄµ¥Ôª£¬±ÈÈ磺Êý×飩¡£PHP Ò²Ö§³ÖÁ½ÖÖ¸´ºÏÀàÐÍ£ºÊý×éºÍ¶ÔÏó¡£ + ÕâÁ½ÖÖÀàÐ;߿ÉÒÔ¸³Öµ¸ø±äÁ¿»òÕß´Óº¯Êý·µ»Ø¡£</simpara> + + <simpara> + µ½Ä¿Ç°ÎªÖ¹£¬PHP/FI 2 µÄÓû§²»Ó¦¸Ã¸Ðµ½Èκεı仯¡£È»¶ø£¬µ±Ðí¶àÆäËüÓïÑÔ + Ϊ֮ŬÁ¦µÄʱºò£¬PHP ÔÚÏàͬµÀ·ÉÏ´Ù½øÁ˱í´ïʽµÄ³É³¤¡£PHP ÊÇÒ»ÖÖÃæÏò±í´ïʽ + µÄÓïÑÔ£¬´ÓÕâÒ»·½ÃæÀ´½²¼¸ºõÒ»Çж¼ÊDZí´ïʽ¡£¿¼ÂǸղÅÎÒÃÇÒѾÑо¿¹ýµÄÀý×Ó£¬ + ¡®$a = 5¡¯¡£¿ÉÒÔÇáËɵĿ´µ½ÕâÀïÓÐÁ½¸öÏà¹ØµÄÖµ£¬ÕûÐͳ£Á¿ '5'£¬¶øÇÒ±äÁ¿ $a + µÄÖµÒ²±»¸üÐÂΪ5¡£µ«ÊÇÊÂʵÊÇ£ºÕâÀïÖ»ÓÐÒ»¸öÏà¹ØµÄ¸½¼ÓÖµ£¬¼´±»·ÖÅäµÄÖµ±¾Éí¡£ + ¸³Öµ²Ù×÷¼ÆËãÐè·ÖÅäµÄÖµ£¬¼´5¡£Êµ¼ÊÉÏ£¬Òâζ×Å¡®$a = 5¡¯£¬²»±Ø¹ÜËüÊÇ×öʲôµÄ£¬ + ÊÇÒ»¸öֵΪ5µÄ±í´ïʽ¡£Òò¶ø£¬Ò»Ð©ÏñÕâÑùµÄ´úÂë¡®$b = ($a = 5)¡¯ºÍ¡®$a =5; $b=5¡¯ + £¨·ÖºÅ±êÖ¾×ÅÓï¾äµÄ½áÊø£©¡£ÒòΪ¸³Öµ²Ù×÷µÄ˳ÐòÊÇÓÉÓÒµ½×óµÄ£¬ÄãÒ²¿ÉÒÔÕâôд + ¡®$b = $a =5¡¯¡£</simpara> + + <simpara> + ÁíÍâÒ»¸öºÜºÃµÄÃæÏò±í´ïʽµÄÀý×Ó¾ÍÊÇǰ¡¢ºóµÝÔöºÍµÝ¼õ¡£ + PHP/FI 2 ºÍ¶àÊýÆäËüÓïÑÔµÄÓû§Ó¦¸Ã±È½ÏÊìϤ±äÁ¿++ºÍ±äÁ¿--·ûºÅ¡£¼´µÝÔöºÍµÝ¼õ + ²Ù×÷·û¡£ÔÚ PHP/FI 2 ÖУ¬Óï¾ä¡®$a++¡¯Ã»ÓÐÖµ£¨²»ÊDZí´ïʽ£©£¬ÕâÑùµÄ»°Äã±ã²»ÄÜΪ + Æä¸³Öµ»òÕßÒÔÈÎºÎÆäËü·½Ê½À´Ê¹ÓÃËü¡£PHP ͨ¹ý½«Æä±äΪÁ˱í´ïʽ£¬Èç C ÓïÑÔ£¬ÔöÇ¿ÁË + µÝÔö/µÝ¼õµÄÄÜÁ¦¡£ÔÚ PHP ºÍ C ÓïÑÔ ÖУ¬ÓÐÁ½ÖÖÀàÐ͵ĵÝÔöǰµÝÔöºÍºóµÝÔö£¬±¾ÖÊ + ÉÏÀ´½²£¬Ç°µÝÔöºÍºóµÝÔö¾ùÔö¼ÓÁ˱äÁ¿µÄÖµ£¬²¢ÇÒ¶ÔÓÚ±äÁ¿µÄÓ°ÏìÊÇÏàͬµÄ¡£²»Í¬µÄÊÇ + µÝÔö±í´ïʽµÄÖµ¡£Ç°µÝÔö£¬Ð´×ö¡®++$variable¡¯£¬ÇóÔö¼ÓºóµÄÖµ£¨PHP ÔÚ¶ÁÈ¡±äÁ¿µÄÖµ + ֮ǰ£¬Ôö¼Ó±äÁ¿µÄÖµ£¬Òò¶ø³ÆÖ®Îª¡®Ç°µÝÔö¡¯£©¡£ºóµÝÔö£¬Ð´×ö¡®$variable++¡¯£¬Çó±äÁ¿ + δµÝÔö֮ǰµÄÔʼֵ£¨PHP ÔÚ¶ÁÈ¡±äÁ¿µÄÖµÖ®ºó£¬Ôö¼Ó±äÁ¿µÄÖµ£¬Òò¶ø½Ð×ö¡®ºóµÝÔö¡¯£©¡£ + ¡¾ÒëÕß×¢:ǰµÝÔö£¬++$a, Ôò¸Ã±í´ïʽµÄÖµ¼Ó1£»ºóµÝÔö, $a++, Ôò¸Ã±í´ïʽµÄÖµ²»±ä¡£¡¿ + </simpara> + + <simpara> + Ò»¸ö³£Óõ½±í´ïʽÀàÐÍÊDZȽϱí´ïʽ¡£ÕâЩ±í´ïʽÇóÖµ0»òÕß1£¬¼´ &false; »òÕß &true; + (·Ö±ðµÄ)¡£PHP Ö§³Ö >£¨´óÓÚ£©£¬>=£¨´óÓÚµÈÓÚ£©£¬ + ==£¨µÈÓÚ£©£¬!=£¨²»µÈÓÚ£©£¬<£¨Ð¡ÓÚ£©£¬<= (СÓÚµÈÓÚ)¡£ÕâЩ±í´ïʽ + ¶¼ÊÇÔÚÌõ¼þÅжÏÓï¾ä£¬±ÈÈ磬<literal>if</literal>Óï¾äÖÐ×î³£Óõġ£ + </simpara> + + <simpara> + ÕâÀÎÒÃǽ«ÒªÑо¿µÄ×îºóÒ»¸öÀý×ÓÊÇ×éºÏµÄ¸³Öµ²Ù×÷·û±í´ïʽ¡£ÄãÒѾ֪µÀÈç¹û + ÏëҪΪ±äÁ¿ $a ¼Ó1£¬¿ÉÒÔ¼òµ¥µÄд¡®$a++¡¯»òÕß¡®++$a¡¯¡£µ«ÊÇÈç¹ûÄãÏëΪ±äÁ¿Ôö¼Ó + ´óÓÚ1µÄÖµ£¬±ÈÈç3£¬¸ÃÔõô×ö£¿Äã¿ÉÒÔ¶à´Îд¡®$a++¡¯£¬µ«ÕâÑùÃ÷ÏÔ²»ÊÇÒ»ÖÖ + ¸ßÐ§ÊæÊʵķ½·¨£¬Ò»¸ö¸ü¼ÓͨÓõÄ×ö·¨ÊÇ¡®$a = $a + 3¡¯¡£¡®$a + 3¡¯ ¼ÆËã $a ¼ÓÉÏ3 + µÄÖµ£¬²¢Çҵõ½µÄÖµÖØÐ¸³Óè±äÁ¿ $a, ÓÚÊÇ $a µÄÖµÔö¼ÓÁË3¡£ÔÚ PHP ¼°ÆäËü + ¼¸ÖÖÀàËÆ C µÄÓïÑÔÖУ¬Äã¿ÉÒÔÒÔÒ»ÖÖ¸ü¼Ó¼ò¶ÌµÄÐÎʽÍê³ÉÉÏÊö¹¦ÄÜ£¬Òò¶øÒ²¸ü¼ÓÇå³þ¿ì½Ý¡£ + Ϊ $a µÄµ±Ç°Öµ¼Ó3£¬¿ÉÒÔÕâÑùд£º$a += 3¡£ÕâÀïµÄÒâ˼ÊÇ¡°È¡±äÁ¿ $a µÄÖµ£¬¼Ó3£¬ + µÃµ½µÄ½á¹ûÔٴηÖÅ䏸±äÁ¿ $a¡±¡£³ýÁ˸ü¼òÂÔºÍÇå³þÍ⣬Ҳ¿ÉÒÔ¸ü¿ìµÄÔËÐС£ + ¡®$a += 3¡¯µÄÖµ£¬Èçͬһ¸öÕý³£¸³Öµ²Ù×÷µÄÖµ£¬ÊǸ³ÖµºóµÄÖµ¡£×¢ÒâËü²»ÊÇ3£¬¶øÊÇ + $a ¼ÓÉÏ3µÄ×éºÏÖµ£¨¼´ÒѾ·ÖÅ䏸 $a µÄÖµ£©¡¾ÒëÕß×¢£ºÕâÀï±í´ïʽ¡®$a += 3¡¯µÄÖµÊÇÊ²Ã´ÄØ£¿ + ²»ÊÇ3£¬Ò²²»ÊÇ $a µÄÔʼֵ£¬¶øÊÇÍê³É +3 ²Ù×÷ºó±äÁ¿ $a µÄÖµ¡¿¡£ + ÈκÎÁ½Î»²Ù×÷·û¶¼¿ÉÒÔʹÓÃÔÚ¸´ÖƲÙ×÷·ûģʽ£¬ÀýÈç¡®$a -= 5¡¯£¨´Ó±äÁ¿ $a µÄÖµÖмõÈ¥5£©£¬ + ¡®$b *= 7¡¯ £¨±äÁ¿ $b ³ËÒÔ 7£©£¬µÈµÈ¡£ </simpara> <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> <![CDATA[ @@ -130,15 +105,12 @@ ]]> </programlisting></informalexample> - If the value of the first subexpression is &true; (non-zero), then - 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. + Èç¹ûµÚÒ»¸ö×Ó±í´ïʽµÄÖµÊÇ &true; £¨·ÇÁ㣩£¬ÄÇô¼ÆËãµÚ¶þ¸ö×Ó±í´ïʽµÄÖµ£¬ + ÆäÖµ¼´ÎªÕû¸ö±í´ïʽµÄÖµ¡£·ñÔò£¬½«ÊǵÚÈý¸ö×Ó±í´ïʽµÄÖµ¡£ </para> <para> - The following example should help you understand pre- and - post-increment and expressions in general a bit better: + ÏÂÃæµÄÀý×ÓÒ»°ãÀ´ËµÓ¦¸Ã¿ÉÒÔÉÔ΢°ïÄãÀí½âǰ¡¢ºóµÝÔöºÍ±í´ïʽ£º <informalexample> <programlisting role="php"> @@ -169,36 +141,31 @@ </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 - this case, a statement has the form of 'expr' ';' that is, an - 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> + ÔÚ±¾ÕµĿªÊ¼£¬ÎÒÃÇ˵¹ýÎÒÃǽ«»áÃèÊö¶àÖÖÓï¾äÀàÐÍ£¬²¢ÇÒÈçͬÐíŵµÄÄÇÑù£¬ + ±í´ïʽ¿ÉÒÔÊÇÓï¾ä¡£¾¡¹ÜÈç´Ë£¬²»ÊÇÿ¸ö±í´ïʽ¶¼ÊÇÒ»¸öÓï¾ä¡£¶øÕâÑùµÄ»°£¬ + Ò»¸öÓï¾ä£¬ËüµÄÐÎʽÊÇ'expr' ';'£¬Ò»¸ö±í´ïʽÓÐÒ»¸ö·ÖºÅ½áβ¡£ÔÚ¡®$b=$a=5;¡¯£¬ + $a=5 ÊÇÒ»¸öÓÐЧµÄ±í´ïʽ£¬µ«ÊÇËüÈ´²»ÊÇÒ»¸öÓï¾ä¡£¡®$b=$a=5;¡¯ È´ÊÇÒ»¸öÓÐЧ + µÄÓï¾ä¡£ + </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 - care about whether it means &true; or &false;. - + ×îºóÒ»¼þÖµµÃÌáÆðµÄÊÂÇé¾ÍÊDZí´ïʽµÄÕæÊµÖµ¡£ÔÚÐí¶àʼþÖУ¬´óÌåÉÏÖ÷ÒªÊÇ + ÔÚÌõ¼þÖ´ÐкÍÑ»·ÖУ¬²»Òª×¨×¢ÓÚ±í´ïʽÖÐÃ÷È·µÄÖµ£¬·´¶øÒª×¢Òâ±í´ïʽµÄ + ÖµÊÇ·ñÊÇ &true; »òÕß &false;¡£ + <!-- (PHP doesn't have a dedicated boolean type) : WRONG, php does. --> - - The constants &true; and &false; (case-insensitive) are the two - possible boolean values. When necessary, an expression is - automatically converted to boolean. See the - <link linkend="language.types.typecasting">section about - type-casting</link> for details about how. + + ³£Á¿ &true; ºÍ &false; £¨´óСдÎ޹أ©ÊÇÁ½ÖÖ¿ÉÄÜµÄ Boolean Öµ¡£Èç¹ûÓÐ + ±ØÒª£¬Ò»¸ö±í´ïʽ½«×Ô¶¯×ª»»Îª Boolean¡£²ÎÕÕ + <link linkend="language.types.typecasting">¹ØÓÚÀàÐÍÌø×ªµÄ²¿·Ö</link>¡£ </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> + PHP ÌṩÁËÒ»Ì×ÍêÕûÇ¿´óµÄ±í´ïʽ£¬¶øÎªËüÌṩÍêÕûµÄÎļþ×ÊÁÏÒѾ³¬³öÁË + ±¾ÊÖ²áµÄ·¶Î§¡£ÉÏÃæµÄÀý×ÓÓ¦¸ÃΪÄãÌṩÁËÒ»¸öºÃµÄ¹ØÓÚʲôÊDZí´ïʽºÍÔõ + Ñù¹¹½¨Ò»¸öÓÐÓõıí´ïʽµÄ¸ÅÄî¡£ÔÚ±¾ÊÖ²áµÄÆäÓಿ·Ö£¬ÎÒÃǽ«Ê¼ÖÕʹÓà + <replaceable>expr</replaceable>À´±íʾһ¸öÓÐЧµÄ PHP ±í´ïʽ¡£ + </simpara> </chapter>