PHP FUNCTIONS - PHP LESSON 12 STUDENTSBLOG100


The working Php functions are same as other programming languages.It can be used number of times in the program. This function will be executed only when it is called in the program.

PHP Function Syntax:


PHP Function Example

Output:
You are learning PHP in StudentsBlog100 Website

Lesson 11  Previous | Lesson 0 | Next Lesson 13

Read more ...

PHP FOR & FOREACH LOOP STATEMENTS - PHP LESSON 11 STUDENTSBLOG100

For Loop:
For loop will be executed if the condition given initially is true. The first part of for loop is for initialization, second is for declaring condition and third part is for Increment/Decrement.

Syntax:

Example:

Output:
Number is - 0
Number is - 1
Number is - 2
Number is - 3
Number is - 4
Number is - 5

Foreach Loop:
The foreach statement is used to loop through arrays and objects.When foreach first starts executing, the internal array pointer is automatically reset to the first element of the array. That is that we don't need to call reset() before a foreach loop.

In the example program, for every loop iteration, the value of the current array 'a's element is assigned to $val and the array pointer is moved by one, until it reaches the last array element.

Syntax:

Example:

Output:
Values are 1
Values are 2
Values are 3
Values are 4
Values are 5

Lesson 10  Previous | Lesson 0 | Next Lesson 12

Read more ...

PHP WHILE & DO WHILE LOOP STATEMENTS - PHP LESSON 10 STUDENTSBLOG100

Php loop statements are
  • While
  • Do While
  • For
  • For each

While Loop:
While loop will be executed if the condition given initially is true. If the condition is false, the coded inside the while loop will not be executed.

Syntax:

Example:

Output:
Print Number - 1
Print Number - 2
Print Number - 3
Print Number - 4

Do - While Loop:
Do While loop will be executed even if the condition given initially is False. That is even If the while condition is false, the coded inside the while loop will be executed once.

Syntax:

Example:

Output:
Print Number - 10
In the above program, initially we have assigned the value for variable a as 10. Now it is entering to loop and printing the value of a. After than a's value is incremented by 1,that is now a's value is 11. Loop closed and checking the while condition. Condition is intimating that it is false.So loop stopped.If condition is true, it will be executed until the while condition is false.

Lesson 9  Previous | Lesson 0 | Next Lesson 11

Read more ...

PHP SWITCH STATEMENT - PHP LESSON 9 STUDENTSBLOG100


In switch statements multiple cases are used. Each case contain one condition. The case which is matched with the switch variable will be executed. 

Syntax:
Example:

Output:
Well done
your grade is : B

In the above program, initially we have declared variable grade as B. And totally six cases are introduced with different conditions. In which the variable grade is assigned as B so case B matched and thus case "B" block is executed.

If none of the case is matched, the default block will be executed.

Lesson 8  Previous | Lesson 0 | Next Lesson 10

Read more ...

PHP IF ELSE & ELSEIF STATEMENTS - PHP LESSON 8 STUDENTSBLOG100


Conditional statements in php are..
  • If statement
  • If else statement
  • elseif statement
If Statement:

Syntax:
Example:
Output:
Above condition is correct

If else Statement:

Syntax:
Example php program to check condition:
Output:
Condition is False

If elseif else Statement:

Syntax:
Example php program to find biggest among 3 numbers:
Output:
b is big

Lesson 7  Previous | Lesson 0 | Next Lesson 9

Read more ...