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.  

How to use multiple files efficiently in vim editor

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I prefer using vim editor.

After doing some experiments and knowing some important commands, I though to share with you. So i have written few commands point wise which may be useful for you while editing multiple files using vim (not GVIM, although these commands are valid there too.)

Video on Drupal for beginners

This video is about Drupal basics for beginners. Those who don't know what is Drupal ? what is CMS? Here is the small introduction on it. Please read before going through this video tutorials.
In this video listed features have been dealt with:

  • Prerequisites before using Drupal Based CMS.
  • Small introduction about WAMP (Windows Apache MySQL and PHP)
  • Drupal’s official website from where you can download Drupal latest version CMS, all modules and themes
  • After downloading and setting up WAMP , it deals with installation process
  • some common issues with Drupal while installation like

    • settings.php file missing, copy default.settings.php and rename it as settings.php in the same folder
    • 8MB memory issue, how to increase it to 16MB
    • MySQL Database missing problem
  • After installing, this video deals with little introduction of block, menu, themes and modules
  • How to post content in blog and forum section
  • How to make dropdown menu items under Aquia Marina theme

In the next video we will elaborate usages of each and every topic like profiles, taxonomy, pathuato, system logs,  file uploads, comments, content type, user management etc.

Basic useful vim commands for everyone

I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands.
This post has only most commonly used vim commands which we use in our day today development activities. This post will be very helpful for those who wish to learn vim editor from the scratch and it can be useful for all other vim users too.

So, first open the file by using vim filename (single file at one time). I will be posting very soon about manipulation on multiple files using vim editor.

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.