Php control structures:
  << h o m e

 

 

-------------------------------------------------------

:::>Trinary operator:

 

Test expression ? Yes-expression : no-expression

 

tests the 'test expression' & if it is true evaluates & returns 'yes expression'; if the test expression is false the 'no expession' is evaluated & returned.

 

Same as:

If (test expression){

Yes expression

} else {

No expression

}

-------------------------------------------------------

 

 

-------------------------------------------------------

:::>if

 

If (conditions){

//stuff to do

}

 

--or--

 

If (conditions){

//stuff to do

} else {

//stuff to do

}

 

--or--

 

If (conditions){

//stuff to do

} elseif (conditions 2){

//stuff to do

} else {

//stuff to do

}

 

If the 'conditions' evaluate to true, the '//stuff to do' is done

-------------------------------------------------------

 

 

-------------------------------------------------------

:::>while

 

While (conditions){

//stuff to do

}

 

Evaluates 'conditions' and runs the code in the brackets as long as the 'conditions' are true

-------------------------------------------------------

 

 

-------------------------------------------------------

:::>do while

 

Do //stuff to do

            while (conditions)

 

alot like 'while' but the stuf is done at least once and then the 'conditions' are evaluated to determine whether or not to 'do' again...

-------------------------------------------------------

 

 

-------------------------------------------------------

:::>for

 

For (initial-expression;termination-check;loop-end-expression){

//stuff to do

}

 

Sets the 'initial expression', make s sure that the 'termination-check' is true, deis the '//stuff to do', then evaluates the 'loop-end-eypression'.

A common example is a counter:

 

for (i=0;i<10;i++){

//will print $i 10 times

Echo ('vartable i =' .$i);

}

-------------------------------------------------------

 

 

-------------------------------------------------------

:::>switch

 

Switch (expression)

{

Case value-1:

            //stuff to do if 'expression' is equal to 'value-1'

            break;          // 'break' is optional

 

Case value-2:

            //stuff to do if 'expression' is equal to 'value-2'

            break;          // 'break' is optional

 

Case value-3:

            //stuff to do if 'expression' is equal to 'value-3'

            break;          // 'break' is optional

//default is optional

 

Default:

            //stuff to do in default situation

            break;          // 'break' is optional

 

}

 

 

Evaluates 'expression' & compares the value to the value in each 'case statement'. If a match is found the '//stuff to do'  is executed and the comparison contiues until a break statement or the end of the switch statement...

An elegant piece of code

-------------------------------------------------------

 

 

-------------------------------------------------------

:::>Exit()

 

Exit()

 

Terminates the execution of the script immediately...

-------------------------------------------------------

 

 

-------------------------------------------------------

:::>die()

 

Die('optional message string')

 

Sends the 'optional message string' to output, then terminates the execution of the script

-------------------------------------------------------

  who is f l u i d consulting?
 

http://www.fluidconsulting.com

  << h o m e