Saturday, 16 September 2017

PHP Flow-Control Statements

In PHP, they are eight (8) flow-control statements. They are :-

  • If Loop
  • If...else Loop
  • If...elseif...else Loop
  • While Loop
  • Do...while Loop
  • Switch Statement
  • For Loop
  • Foreach Loop

Let me explain, each of them with a suitable examples.

Analyse the following screenshot:-

The code of the above page, is as follows:-


When we click on the "examples" of "If Loop", the output will be :-


The code of the above page, is as follows:-



When we click on the "examples" of "If..Else Loop", the output will be :-


The code of the above page, is as follows:-


When we click on the "examples" of "If..Elseif...Else Loop", the output will be :-

The code of the above page, is as follows:-


When we click on the "examples" of "While Loop", the output will be :-



The code of the above page, is as follows:-


When we click on the "examples" of "Do...While Loop", the output will be :-


The code of the above page, is as follows:-


When we click on the "examples" of "Switch" Statement, the output will be :-


The code of the above page, is as follows:-



When we click on the "examples" of "For Loop", the output will be :-

The code of the above page, is as follows:-


When we click on the "examples" of "Foreach Loop", the output will be :-

The code of the above page, is as follows:-





Friday, 15 September 2017

PHP Operators

Operators :-

Operators are used to perform operations on variables and values.

PHP divides the operators in the following groups:
  • Arithmetic operators
  • Assignment operators
  • Comparison operators
  • Increment/Decrement operators
  • Logical operators
  • String operators
  • Array operators
  • Bitwise operators

Let us understand all the operators with an example. Consider the following screenshot:-


This is the main page, containing the example links of all the operators in PHP. The code of the above page is as follows:-


Now, when I click on the "examples" of "Arithmetic operators", the output will be like this - 

The code for the above page is as follows:- 


When I click on the "examples" of "Assignment operators", the output will be like this - 


The code for the above page is as follows:- 



When I click on the "examples" of "Comparison operators", the output will be like this - 




The code for the above page is as follows:- 



When I click on the "examples" of "Increment/Decrement operators", the output will be like this - 



The code for the above page is as follows:- 


When I click on the "examples" of "Logical operators", the output will be like this - 


The code for the above page is as follows:-


When I click on the "examples" of "String operators", the output will be like this - 


The code for the above page is as follows:-



When I click on the "examples" of "Array operators", the output will be like this - 
The code for the above page is as follows:-


When I click on the "examples" of "Bitwise operators", the output will be like this - 


The code for the above page is as follows:-


Sunday, 20 September 2015

Some Array Functions:-

  1. array_diff() :- 
    •  The array_diff() function compares the values of two(or more) arrays, and returns the differences.
    • This function compares the values of two(or more) arrays, and return an array that contains the entire from array1 that are not present in array2 or array3 etc.
    • It can be explained further with a suitable example:-
                    array_diff().php:-
                   

                     Screenshot:-
                      

    2. array_intersect() :-
    • The array_intersect() function compares the values of two(or more) arrays, and returns the matches.
    • This function compares the values of two or more arrays, and return an array that contains the entries from array1 that are present in array2, array3 etc.
    • Now, explain it with a suitable example:-
                    array_intersect().php:-
                   

                    Screenshot:-
                     

     3.  array_push() ;-
    • The array_push() function inserts one or more elements to the end of an array.
    • Lets see an example:-
                    array_push().php :-
                    

                    Screenshot:-
                     

     4. array_pop() :-
    • The array_pop() function deletes the last element of an array.
    • Let consider an example:-
                    array_pop().php:-
                    

                     Screenshot:-
                      


     5. array_unique() ;-
    • The array_unique() function removes duplicate values from an array.
    • If two or more array values are the same, the first appearance will be kept and the other will be removed.
    • The returned array will keep the first array item's key type.
    • Consider an example:-
                     array_unique().php:-
                     

                     Screenshot:-
                     

     6. array_count():-
    • The array_count() function returns the number of elements in an array.
    • Consider an example:-
                    array_count().php:-
                     

                      Screenshot:-
                      

      7. array_merge() ;-
    • The array_merge() function merges one or more arrays into one array.
    • We can assign one array to the function, or as many as we like.
    • If two or more array elements have the same key, the last one overrides the others.
    • Let us consider an example:-
                    array_merge().php:-
                    

                     Screenshot:-