P. 1
Write Simple Program to Display the Current Date

Write Simple Program to Display the Current Date

|Views: 2|Likes:
Published by Rama Krishna
Write Simple Program to Display the Current...
Write Simple Program to Display the Current...

More info:

Categories:Types, Research
Published by: Rama Krishna on Feb 16, 2013
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as DOCX, PDF, TXT or read online from Scribd
See more
See less





Write simple program to display the current date To develop the first program of PHP, you need to have

a web server like: Apache Tomcat , IIS etc. Another way to develop PHP program. WAMP is a kind of stack of software collection, WAMP is the acronym for Windows, Apache, MySQL, and PHP. WAMP server is one of the popular server use for PHP. It is free and you can download it from http://www.wampserver.com/en/download.php (you can copy and paste this link in the browsers address bar). After downloading the .exe file, install this file (normal installation as we do for other software package), For downloading and installing please visit our web site:http://roseindia.net/tutorial/php/phpbasics/Downloading-Installing-Wamp.html For starting the WAMP server: http://roseindia.net/tutorial/php/phpbasics/Running-Testing-Wamp.html Now to develop the first program do as follows: Exmaple 1: <?php echo date("l"); ?> Output: Tuesday In PHP date() is a predefined function which returns a string value, depends on the parameter passed. Array in PHP Almost every language supports array, which is a collection of similar data type, but in PHP language it could be or could not be the same. An array could be a collection of similar or dissimilar datatype. PHP Array Example 1: <?php

122. $array=array("These". echo"An array with dissimilar datatype". var_dump($array). ?> Output: An array with similar datatype array(3) { [0]=> string(5) "These" [1]=> string(3) "are" [2]=> string(7) "similar" } An array with dissimilar datatype array(5) { [0]=> string(6) "String" [1]=> int(122) [2]=> float(34.echo"An array with similar datatype".'v').true. $array=array("String"."similar")."<br/>"."are"."<br/>". var_dump($array).34.34.34) [3]=> bool(true) [4]=> .

"similar"). ?> Output: An array with similar datatype array(3) { [0]=> string(5) "These" [1]=> string(3) "are" [2]=> string(7) "similar" } var_dump() is a function which is used to print the elements of an array Another function is print_r(). $array=array("These". var_dump($array). echo "<br/>Another function is print_r(). echo"var_dump() is a function which is used to print the elements of an array". which is used to print an array Array ( [0] => These [1] => are .string(1) "v" } Array in PHP with Example 2: <?php echo"An array with similar datatype". which is used to print an array<br/>". print_r($array)."are"."<br/>".

$array=array(1=>"This"."numeric". var_dump($array)."s"=>2. echo"This is an example of associative array<br/>".23)."array")."is". var_dump($array).[2] => similar ) Example 3: <?php echo"This is an example of numeric array<br/>". ?> Output: This is an example of numeric array array(4) { [0]=> string(4) "This" [1]=> string(2) "is" [2]=> string(7) "numeric" [3]=> string(5) "array" } This is an example of associative array array(3) { [1]=> string(4) "This" .3=>23. $array=array("This".

$array=array( "string"=>array( "This".2.["s"]=> int(2) [3]=> float(23. "array").34)). "is". "multidimensional".23) } Example 4: <?php echo "This is an example of numeric array<br/>". ?> Output: This is an example of numeric array array(2) { ["string"]=> array(4) { [0]=> string(4) "This" [1]=> string(2) "is" [2]=> string(14) "multidimensional" [3]=> string(5) "array" } ["numeric"]=> . "numeric"=>array(1. var_dump ($array).223.2.

It support addition.array(5) { [0]=> int(1) [1]=> int(2) [2]=> int(2) [3]=> int(223) [4]=> int(34) } } Mathematical Operations in PHP PHP supports mathematical operations as other languages do. $c=$a+$b. $c=$a*$b. subtraction. decrement etc. $b=5. division. echo "<br/> Subtraction of $a and $b is=$c". multiplication. $c=$a-$b. . increment. echo "<br/> Addition of $a and $b is=$c". Example 1: <?php $a=25.

echo "<br/> Multiplication of $a and $b is=$c". echo "<br/> Division of $a and $b is=$c". $a++. . echo "<br/> After Decrement value of \$b is=$b". $c=$a/$b. echo "<br/> After Increment value of \$a is=$a". $b--. The given examples will help to understand how you can put them to work. ?> Output: Addition of 25 and 5 is=30 Subtraction of 25 and 5 is=20 Multiplication of 25 and 5 is=125 Division of 25 and 5 is=5 Before Increment value of $a is=25 After Increment value of $a is=26 Before Decrement value of $b is=5 After Decrement value of $b is=4 PHP User Defined Function An user-defined function saves us from rewriting the same code again and again and helps us to make our application smaller. echo "<br/> Before Decrement value of \$b is=$b". echo "<br/> Before Increment value of \$a is=$a".

..$second).. $second=13. } $first=12.add($first.. /*You might know these variables are * different from the parameters of add function. more than one or no parameter. echo "function add will return=". Example 1: <?php function add($first.]){ PHP code} mixed is the datatype that means it could be of any datatype.. */ ?> Output: function add will return=25 Example 2: . one function could have one. $var: is the name of the parameter. General structure of the user defined function is: function function_name([mixed $var. besides that you can make your own functions as per the need.PHP has so many built-in functions.$second) { return ($first+$second).

?> Output: . echo "function add will return=". } echo "We are outside the function<br/> ".add($first). } $first=100.$second=23) { return ($first+$second).<?php function add($first.". one(). ?> Output: function add will return=123 Example 3: <?php function one() { echo "We are inside the function.

"is". echo"<br/><b>After calling string_push function</b><br/>". var_dump($array)."new"). ?> Output: Before calling string_push function array(3) { [0]=> string(4) "This" [1]=> string(2) "is" [2]=> string(3) "new" . $array=array($array.We are outside the function We are inside the function."array").$str)). } $array=array("This". echo"<br/><b>Before calling string_push function</b><br/>". var_dump($array).$str) { return(array_push($array. Example 4: <?php function string_push($array.

} After calling string_push function array(2) { [0]=> array(3) { [0]=> string(4) "This" [1]=> string(2) "is" [2]=> string(3) "new" } [1]=> string(5) "array" } .

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->