PHP for beginners -Lesson 7

INTERRUPTING LOOPS(break and continue) IN PHP
 
1. Break keyword
    The PHP break keyword is used to terminate the execution of a loop prematurely.
    Once break statement executed , it immediately terminates the loop and no further iterations are made.
  In the following example the condition test becomes true when the counter value reaches  five:

PHP for beginners -Lesson 6

WHILE LOOP IN PHP
 
Code will execute continue till condition reached false.
Syntax:
initialization – set your counter above while loop while (condition)
  {
  code here…
   
  increment/decrement
  }
 
Parameters :  
  condition – Loop will continue till condition is TRUE.
  increment/decrement – increase or decrease your counter , this parameter should be before end of loop.  

PHP for beginners -Lesson 5

LoopingFOR LOOP IN PHP

Code will execute continue till condition reached false.
Syntax: for (initialization; condition; increment/decrement) { code here… }

Parameters :
initialization – set your counter, execute only once.
condition – Loop will continue till condition is TRUE.
increment/decrement – increase or decrease your counter , this parameter will execute at end of loop.

Example 1 : Display 1 to 5 numbers using For loop. <?php $i=1; for( $i = 1; $i <= 5; $i++ ){ echo $i."\t"; // \t use for TAB } ?>

Output : 1 2 3 4 5

Example 2 : Display table of input number <?php $no=5; for( $i = 1; $i <= 10; $i++ ){ echo $no*$i."\t"; } ?>

Output: 5 10 15 20 25 30 35 40 45 50

Example 3 : Fibonacci series
What is Fibonacci Numbers?
Below sequence called Fibonaci series
0,1,1,2,3,5,8,13,21,34,55,89,,144………. (f3 =f2+f1 and given f1=0, f2=1)

By definition, the first Fibonacci number is 0 and second Fibonacci number is 1. Then each subsequent number is calculated based on sum of the previous two. <?php $f1 = 0; $f2 = 1; $range = 10; for ( $i = 2; $i < $range; $i++ ){ $fn = $f1 + $f2; echo $fn."\t"; $f1 = $f2; $f2 = $fn; } ?>

Output : 1 2 3 5 8 13 21 34

Example 4 : Prime number from 1 to 100
A Prime Number can be divided – only by 1 or itself. And it must be a whole number greater than 1

<?php for( $i = 1; $i <= 100; $i++ ){ for( $j = 2; $j <= $i-1; $j++ ){ if( $i % $j == 0) break; } if($j==$i) echo $j."\t"; } ?>

Output : 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97

 

PHP for beginners -Lesson 4

Minimal Basics on Switch statements

What is switch statement in php ?
Switch is a conditional statement , which perform specific action according to various condition. It is equivalent to If else strcutures.
Syntax :

[php]switch (variable) {
    case label1:
        This block will execute if variable=label1;
    break;
    case label2:
        This block will execute if variable=label2;
    break;
    case label3:
        This block will execute if variable=label3;
    break;
    default:
        This block will execute if variable not matching with any label;
}
[/php]
variable can be integer,string, character, float, double etc..
switch is similar to if..elseif..esle statement.
Note : break is required , if you missed break then it will check next case and execute default case also.

<?php
$num = 2;
switch($num){
case 1:
echo "My number is One";
break;
case 2:
echo "My number is Two";
break;
case 3:
echo "My number is Three";
break;
default :
echo "Not matching";
}
?>

Output : My number is Two

1. Checking vowel & consonant(Only for Small case letter) <?php
$c = 'u';
switch($c){
case 'a':
echo "$c is Vowel";
break;
case 'e':
echo "$c is Vowel";
break;
case 'i':
echo "$c is Vowel";
break;
case 'o':
echo "$c is Vowel";
break;
case 'u':
echo "$c is Vowel"; break;
default:
echo "$c is Consonant ";
}
?>

Output : u is Vowel

 
2. Wishing birthday on current date

<?php $dob = date("d/m");
switch($dob){ case "10/02":
echo "Happy birthday Somnath";
break;
case "23/07":
echo "Happy birthday Santosh";
break;
case "18/08":
echo "Happy birthday Anil";
break;
case "04/09":
echo "Happy birthday Jassi";
break;
case "11/12":
echo "Happy birthday Ritesh";
break;
default: echo "No birthday party";
} ?>

if Today's date is – 23/07/2011
Output : Happy birthday Santosh

PHP for beginners -Lesson 3

In this tutorial we will discuss about various ways to write if else condition with basic example.

If Statement Syntax :

if (condition){
    code to be executed if condition is true;
}

Sample Code :

PHP for beginners -Lesson 2

Usages of echo, print, print_r, var_dump(), printf()

Echo:
1) echo does not return a value.
2) This is faster than 'print' (*)
3) You can pass multiple expression

Print:
1) print return a value
2) This is slower than echo (*)
3) it takes single expression

PHP for beginners -Lesson 1

Hey guys,
We will be updating basic to advanced level PHP tutorials by examples which will help all PHP programmers whether he/she is  novice or professional one.
In this lesson we will show you how to print values on browser. Basically there are  5 ways to print the output value on browser.

What is Google WAVE and PROJECT NATAL

natalA GOOGLE Wave is an application by google that collaborates several Google features. A user who has installed Google wave will be able to access and use Google features like Orkut, Google Talk and Gmail efficiently.
Google wave can also check for errors (grammatical and spelling) as well translate text to forty different languages. Google has not yet announced when Wave will be released.

For the User’s Convenience, Google will open source part of the code so that users can develop or Modify the features of the program. Upcoming days ,  no need to use of different browser , in Single place you can use all features of google.    Microsoft is working on Project Known as ‘NATAL’ , which on completion would probably be the new face of gaming. It involves gaming without the use of any controllers. End users will be able to play games or interact with the interface with gestures and spoken commands on their existing Xbox consoles. The device would be around nine inches and a motion sensor would be placed either above or below the device. It would feature face and voice recognition as well as full body 3D  motion capturing capabilities.

Observers are expecting it to be launched up to end of 2010.

How to find out , who is Invisible (In Gmail)

offline line User There is simple trick to find out Invisible user. The Gmail Chat application that is present on the left pane of the site allows users to appear 'Invisible'  to their contact. For this , You will need the 'Google Talk' desktop application. One you have logged on to your account, follow these steps to determine which of your contacts is invisible :

  • Open 'Google Talk' chat application
  • Search for contact by typing his/her name in the search box
  • Once the name of the contact shows up in the contact list click the entry to open the chat window.

  • Click the dropdown arrow present under the close button and click ‘Go off the record’ .
  • If you  receive a message saying , “<user ID> @ gmail.com is offline and can’t receive messages right now’  then user is logged off".
  • If the above message does not appear after you send a message then user is invisible mode.

This trick is working in most cases so far. However , there may be varying results in case of users who log on to Google talkusing third party tools like mobile chat applications.