Page 100 - Open Soource Technologies 304.indd
P. 100

Unit 6: Building Blocks of PHP



            {                                                                                     Notes

               return $i*2;

            }
            $b = $a = 5;     /* assign the value five into the variable $a and $b */
            $c = $a++;       /* post-increment, assign original value of $a

                             (5) to $c */

            $e = $d = ++$b;  /* pre-increment, assign the incremented value of
                             $b (6) to $d and $e */

                             /* at this point, both $d and $e are equal to 6 */

            $f = double($d++);   /* assign twice the value of $d before
                             the increment, 2*6 = 12 to $f */

            $g = double(++$e);   /* assign twice the value of $e after
                             the increment, 2*7 = 14 to $g */

            $h = $g += 10;  /* first, $g is incremented by 10 and ends with the
                             value of 24. the value of the assignment (24) is

                             then assigned into $h, and $h ends with the value

                             of 24 as well. */

            ?>
            Some expressions can be considered as statements. 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.

            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. The constants TRUE and FALSE (case-
            insensitive) are the two possible boolean values. When necessary, an expression is automatically
            converted to boolean. See the section about type-casting for details about how.

            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 expr to indicate any valid PHP expression.
            6.1.5 PHP Constants

            Constants and variables is that constant value can not be changed in the process of running
            program. It can be mathematic constants, passwords, paths to files, etc. By using a constant
            you “lock in” the value which prevents you from accidentally changing it. If you want to run a
            program several times using a different value each time, you do not need to search throughout



                                             LOVELY PROFESSIONAL UNIVERSITY                                    95
   95   96   97   98   99   100   101   102   103   104   105