.


:




:

































 

 

 

 





PHP . , , , ( ). . . . .

PHP . , .

- __FILE__ and __LINE__, , .

6-1. __FILE__ __LINE__ <?phpfunction report_error($file, $line, $message) { echo "An error occured in $file on line $line: $message.";} report_error(__FILE__,__LINE__, "Something went wrong!");?>

define() undefine().

6-2. <?phpdefine("CONSTANT", "Hello world.");echo CONSTANT; // outputs "Hello world."undefine ("CONSTANT");?>

- PHP. PHP . - "-, ".

, . "$a = 5", '5' $a. '5', , 5, '5' 5 ( '5' ).

$a 5, , $b = $a, , $b = 5. , $a 5. , .

- . , :

function foo () { return 5;}

, ( , , ), , $c = foo() , $c = 5 . - , . foo() 5, 'foo()' - 5. , .

, PHP . PHP 3 : , ( "" , , , ). PHP 2 () : . .

, PHP/FI 2 - . PHP , , . , , '$a = 5'. , - 5 $a, 5. , . , - 5. , '$a = 5', , 5. , '$b = ($a = 5)' '$a = 5; $b = 5;' ( ). , '$b = $a = 5'.

. PHP/FI 2 variable++ and variable--. . PHP/FI 2, '$a++' ( ), - . PHP / , C. PHP, C, 2 - . . . , '++$variable', (PHP , ). 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').

. 0 1 ( ). PHP > (, ), >= ( ), = (), < (,) <= ( ). , IF.

, , -. , , $a , '$a++' '++$a'. , , - 3? '$a++' , . '$a = $a + 3'. '$a + 3' , $a 3, $a, $a 3. PHP, C, , . 3 $a '$a+=3'. : ' $a, 3 $a. , , . '$a+=3' . , 3, $a 3. ( 2 - . .) , : '$a-=5' ( 5 $a), '$b*=7' ( $a 7) .

, , - :

$first? $second: $third

( 0), . .

?

function double($i) /* */
{
return $i*2;
}
$b = $a = 5; /* $a $b */
$c = $a++; /* , $c $a (5)*/
$e = $d = ++$b; /* , $d $e $b (6) */
/* $d $e 6 */
$f = double($d++); /* $d , 2*6 = 12, $f*/
$g = double(++$e); /* $e , 2*7 = 14, g */
$h = $g += 10; /* $g 10, 24, $h, 24 */

, , . , . '' ';', , . '$b=$a=5;' $a=5 , . '$b=$a=5;' .

, - . , , , TRUE FALSE ( PHP boolean). , Perl. - TRUE, - FALSE. , - TRUE. '0' FALSE; - TRUE. ( ) - , FALSE; TRUE.

PHP . , . 'expr' PHP.

IF

IF , PHP. . PHP IF C:

if (expr) statement

, "expr". expr TRUE, PHP "statement", FALSE - .

'a is bigger than b' $a $b:

if ($a > $b) print "a is bigger than b";

. , IF. . , , $a $b:

if ($a > $b) { print "a is bigger than b"; $b = $a; }

IF IF, .

ELSE

, - . ELSE. ELSE IF , FALSE. 'a is bigger than b' $a $b, 'a is NOT bigger than b' :

if ($a > $b) { print "a is bigger than b"; } else { print "a is NOT bigger than b"; }

ELSE IF FALSE, ELSEIF - FALSE (. ).

ELSEIF

ELSEIF, , IF ELSE. ELSEIF ELSE , IF FALSE, ELSE ELSEIF TRUE. , 'a is bigger than b' $a>$b, 'a is equal to b' $a==$b, 'a is smaller than b' $a<$b:

if ($a > $b) { print "a is bigger than b";} elseif ($a == $b) { print "a is equal to b";} else { print "a is smaller than b";}

IF ELSEIF. ELSEIF ( ), TRUE, . PHP3 'else if' ( ), , 'elseif' ( ).

ELSEIF IF ELSEIF FALSE, ELSEIF TRUE.

IF: IF():... ENDIF;

PHP3 IF. HTML IF, . "IF()" , ENDIF. :

<?php if ($a==5):?> A = 5 <?php endif;?>

"A = 5" IF, . HTML $a 5.statement written in the alternative syntax.

ELSE ELSEIF (expr). :

if ($a == 5): print "a equals 5"; print "...";elseif ($a == 6): print "a equals 6"; print "!!!";else: print "a is neither 5 nor 6";endif;

WHILE

WHILE - PHP3. C. WHILE:

WHILE(expr) statement

WHILE . PHP () () expr TRUE. , , ( - ). , expr FALSE , .

IF, :

WHILE(expr): ... ENDWHILE;

- 1 10:

/* example 1 */ $i = 1;while ($i <= 10) { print $i++; } /* example 2 */ $i = 1;while ($i <= 10): print $i; $i++;endwhile;




:


: 2015-09-20; !; : 503 |


:

:

, ; , .
==> ...

1587 - | 1376 -


© 2015-2024 lektsii.org - -

: 0.024 .