Introduction to PHP

PHP stands for  Hypertext Preprocessor.It is a server-side scripting language.It is an open source software and free to download and use.

PHP files have a file extension of ".php", ".php3", or ".phtml".

 

PHP script:

PHP scripting block always starts with

Each code line in PHP must end with a semicolon. The semicolon is a separator and is used to distinguish one set of instructions from another.

variables :

All variables will start with $ symbol.

Simple example

$var_name = value;

 

condition statement:

All the condition statement syntax are same as in C language.Example if..else,switch.

Array:

Array is a homogenious collection of elements.

$arr[0]="12345";

echo $arr[0];

 

There are 3 types of arrays

1)Numerical arrays

2)Associative array

3)Multi dimensional arrays

 

Numerical arrays:

A numeric array stores each array element with a numeric index.

$type=array("cat","dog","rat");

Internally it will store as

$type[0]="cat";
$type[1]="dog";
$type[2]="rat";

 

Example

$type[0]="cat";
$type[1]="dog";
$type[2]="rat";
echo $type[0] . " kills " . $type[2];
?>

 

Associative array:

In associative array the index is replaced with a value.

$names = array("ravi"=>40, "rani"=>45, "ram"=>50);

$names['ravi']="40";

$names['rani']="45";

$names['ram']="50";

example:

$names['ravi']="40";

$names['rani']="45";

$names['ram']="50";


echo "marks of ravi,rani,ram are". $names['ravi'] .$names['rani']. $names['ram'];
?>


Loops:

All the loop statement syntax also similar as in C language.

example:

WHILE

while (condition)
{
code to be executed;
}

 

example:

$temp=0;

while($temp<=10)

{

echo "The number is" . $temp ;

$temp++;

}

?>

 

DO-WHILE

do
{
code to be executed;
}
while (condition);

example:

$temp=0;

do

{

echo "The number is" . $temp ;

$temp++;

}while($temp<=10)

?>

FOR

for (init; condition; increment)
{
code to be executed;
}

example:

for($temp=0;$temp<=10;$temp++;)

{

echo "The number is" . $temp ;

}

?>

 

 

 

 


 

 

 

 


Like it on Facebook, Tweet it or share this article on other bookmarking websites.

Comments (0)

There are no comments posted here yet

Is our army's deaths are in vain as Indian goverment is not taking any strict action against pakistan ?

No answer selected. Please try again.
Please select either existing option or enter your own, however not both.
Please select minimum 0 answer(s) and maximum 2 answer(s).
/polls/day-to-day-issues/6622-is-our-army-s-deaths-are-in-vain-as-indian-goverment-is-not-taking-any-strict-action-against-pakistan.json?task=poll.vote
6622
radio
[{"id":"23034","title":"Yes","votes":"22","type":"x","order":"1","pct":64.71,"resources":[]},{"id":"23044","title":"No","votes":"12","type":"x","order":"2","pct":35.29,"resources":[]}] ["#ff5b00","#4ac0f2","#b80028","#eef66c","#60bb22","#b96a9a","#62c2cc"] ["rgba(255,91,0,0.7)","rgba(74,192,242,0.7)","rgba(184,0,40,0.7)","rgba(238,246,108,0.7)","rgba(96,187,34,0.7)","rgba(185,106,154,0.7)","rgba(98,194,204,0.7)"] 350
bottom 200
No married couple wants to end up getting divorced. It is not like they have planned for it. They try to put up with their partners for as long as they
Due to our modern lifestyle, we feel that digestion related disorders are a common problem. Thus, we neither give importance to them nor seek any help
The bond of marriage brings the two people together. Initially, everything may seem okay and both of them slowly start discovering each other in the journey.
The Growth Story of India Most of the developed world thinks that India is a backward country and you can find comments to such effect spread all over
It's been two weeks since Apple has announced their smart watch or simply - Watch, along with iPhone 6 and the release of iOS 8. Apple Watch is not yet
New technologies in the dynamic arena of IT keep on certain flares in the media and on the net. It must have wondered how fast this growth engine is. But
In Android, just like in Windows, if you want to view a document containing a non-Unicode font, the font must be installed in the system first. Now the
Introduction:  The power of connectivity cannot be overstated if you use mobile phone for calls and text messages. If your mobile phone as sufficiently