Sunday, 22 December 2013
Wednesday, 18 December 2013
Switch in PHP examples
Example No.1
<?php
$week = "Friday";
switch($week)
{
case "Sunday":
echo "Today is Sunday";
break;
case "Monday":
echo "Today is Monday";
break;
case "Tuesday":
echo "Today is Tuesday";
break;
case "Wednesday":
echo "Today is Wednesday";
break;
case "Thursday":
echo "Today is Thursday";
break;
case "Friday":
echo "Today is Friday";
break;
case "Saturday":
echo "Today is Saturday";
break;
}
?>
output:
Today is Friday
Example No.2
using default in switch
<?php
$week = "Notavailble";
switch($week)
{
case "Sunday":
echo "Today is Sunday";
break;
case "Monday":
echo "Today is Monday";
break;
case "Tuesday":
echo "Today is Tuesday";
break;
case "Wednesday":
echo "Today is Wednesday";
break;
case "Thursday":
echo "Today is Thursday";
break;
case "Friday":
echo "Today is Friday";
break;
case "Saturday":
echo "Today is Saturday";
break;
default:
echo "This weekend is not availabe in our list";
}
?>
output:
This weekend is not availabe in our list
Example NO.3
Always used break keyword in the end of case body.Otherwise you got wrong output.Following example shows What you got when you did not used break keyword
<?php
$week = "Sunday";
switch($week)
{
case "Sunday":
echo "Today is Sunday";
case "Monday":
echo "Today is Monday";
case "Tuesday":
echo "Today is Tuesday";
case "Wednesday":
echo "Today is Wednesday";
case "Thursday":
echo "Today is Thursday";
case "Friday":
echo "Today is Friday";
case "Saturday":
echo "Today is Saturday";
default:
echo "This weekend is not availbe in our list";
}
?>
output:
Today is SundayToday is MondayToday is TuesdayToday is WednesdayToday is ThursdayToday is FridayToday is SaturdayThis weekend is not availbe in our list
<?php
$week = "Friday";
switch($week)
{
case "Sunday":
echo "Today is Sunday";
break;
case "Monday":
echo "Today is Monday";
break;
case "Tuesday":
echo "Today is Tuesday";
break;
case "Wednesday":
echo "Today is Wednesday";
break;
case "Thursday":
echo "Today is Thursday";
break;
case "Friday":
echo "Today is Friday";
break;
case "Saturday":
echo "Today is Saturday";
break;
}
?>
output:
Today is Friday
Example No.2
using default in switch
<?php
$week = "Notavailble";
switch($week)
{
case "Sunday":
echo "Today is Sunday";
break;
case "Monday":
echo "Today is Monday";
break;
case "Tuesday":
echo "Today is Tuesday";
break;
case "Wednesday":
echo "Today is Wednesday";
break;
case "Thursday":
echo "Today is Thursday";
break;
case "Friday":
echo "Today is Friday";
break;
case "Saturday":
echo "Today is Saturday";
break;
default:
echo "This weekend is not availabe in our list";
}
?>
output:
This weekend is not availabe in our list
Example NO.3
Always used break keyword in the end of case body.Otherwise you got wrong output.Following example shows What you got when you did not used break keyword
<?php
$week = "Sunday";
switch($week)
{
case "Sunday":
echo "Today is Sunday";
case "Monday":
echo "Today is Monday";
case "Tuesday":
echo "Today is Tuesday";
case "Wednesday":
echo "Today is Wednesday";
case "Thursday":
echo "Today is Thursday";
case "Friday":
echo "Today is Friday";
case "Saturday":
echo "Today is Saturday";
default:
echo "This weekend is not availbe in our list";
}
?>
output:
Today is SundayToday is MondayToday is TuesdayToday is WednesdayToday is ThursdayToday is FridayToday is SaturdayThis weekend is not availbe in our list
Call by refrence in PHP
Following example show orignal value of parameter change.
<?php
function orignalValueChange(&$refParameter)
{
$refParameter = 4;
}
$var = 23;
orignalValueChange($var);
echo $var;
?>
output:
4
Following example show orignal value of parameter not change.
<?php
function orignalValuenotChange($refParameter)
{
$refParameter = 4;
}
$var = 23;
orignalValuenotChange($var);
echo $var;
?>
output:
23
function callbyref(&$para1, &$para2,&$para3)
{ $para1 = $para2 = $para3;
}
$var1 = 1000;
$var2 = 2000;
$var3 = 3000;
callbyref($var1, $var2,$var3);
$var2 = 5;
echo "<br/>";
echo $var1;
?>
output:
3000
<?php
function orignalValueChange(&$refParameter)
{
$refParameter = 4;
}
$var = 23;
orignalValueChange($var);
echo $var;
?>
output:
4
Following example show orignal value of parameter not change.
<?php
function orignalValuenotChange($refParameter)
{
$refParameter = 4;
}
$var = 23;
orignalValuenotChange($var);
echo $var;
?>
output:
23
Example
<?phpfunction callbyref(&$para1, &$para2,&$para3)
{ $para1 = $para2 = $para3;
}
$var1 = 1000;
$var2 = 2000;
$var3 = 3000;
callbyref($var1, $var2,$var3);
$var2 = 5;
echo "<br/>";
echo $var1;
?>
output:
3000
Tuesday, 17 December 2013
Infinite loop using for loop and while loop in PHP
Followings scripts shows how to run a loop infinite.
<?php
for(; ;)
{
echo "infinte loop";
}
?>
<?php
while(true)
{
echo "infinte loop";
}
?>
Example 1
Using For loop<?php
for(; ;)
{
echo "infinte loop";
}
?>
Example2
Using While Loop<?php
while(true)
{
echo "infinte loop";
}
?>
Monday, 16 December 2013
Server Side PHP Date convert in javascript format.
Server Side PHP Date convert in javascript format.
Javascript is a client side scripting language.So when we dealing with dates in javascript.Some time we need the current date of Server using javascript.So we can get a unix time stamp in PHP using strtotime() function in PHP
So following Script give you server Side Date and time in Javascript.
Example
<script type="text/javascript">
var ServerSide = <?=strtotime("now")?>;
var today = new Date(ServerSide * 1000);
alert(today);
</script>
output
Thanks for reading
Sunday, 15 December 2013
Table backup with data in sql server through generate script
We have a following table name tblEmployee in customersdatbs database and we want to back up the table with data through generate script
Step 2
Right click on database.Go to Task=>Generate Script seect.
step 3
step3
Step 4
Step5
step 6Step 7
Step 8
Step 9 Final Step
USE [customersdatbs]
GO
/****** Object: Table [dbo].[tblEmployee] Script Date: 12/15/2013 13:06:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tblEmployee](
[employeeid] [int] IDENTITY(1,1) NOT NULL,
[name] [varchar](50) NULL,
[gender] [nvarchar](50) NULL,
[city] [nvarchar](50) NULL,
CONSTRAINT [PK_tblEmployee] PRIMARY KEY CLUSTERED
(
[employeeid] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
SET IDENTITY_INSERT [dbo].[tblEmployee] ON
INSERT [dbo].[tblEmployee] ([employeeid], [name], [gender], [city]) VALUES (2, N'name1', N'female', N'karachi')
INSERT [dbo].[tblEmployee] ([employeeid], [name], [gender], [city]) VALUES (3, N'name2', N'female', N'karachi')
INSERT [dbo].[tblEmployee] ([employeeid], [name], [gender], [city]) VALUES (4, N'name3', N'female', N'karachi')
INSERT [dbo].[tblEmployee] ([employeeid], [name], [gender], [city]) VALUES (5, N'name4', N'male', N'kpk')
SET IDENTITY_INSERT [dbo].[tblEmployee] OFF
Save the script for future use
Thanks for reading
if else in PHP example
If condition always run when condition is true e.g if(true){}
Example No.1
<?php
$true = true;
$false = false;
if($true == true)
{
echo "This is true";
}else
{
echo "This is flase";
}
?>
ouput:
This is true
Example No.2
<?php
$true = true;
$false = false;
if($true == $false)
{
echo "I like mango";
}else
{
echo "I like appple";
}
?>
ouput:
I like appple
Example No.3
<?php
$true = true;
$false = false;
if($true!== $false)
{
echo "I like mango";
}else
{
echo "I like appple";
}
?>
ouput:
I like mango
Example No.4
Using string comparison
<?php
$string1 = "BMW";
$string2 = "BMW";
if($string1 == $string2)
{
echo $string1." ".$string2;
}else
{
echo "It is else";
}
?>
ouput:
BMW BMW
Example No.1
<?php
$true = true;
$false = false;
if($true == true)
{
echo "This is true";
}else
{
echo "This is flase";
}
?>
ouput:
This is true
Example No.2
<?php
$true = true;
$false = false;
if($true == $false)
{
echo "I like mango";
}else
{
echo "I like appple";
}
?>
ouput:
I like appple
Example No.3
<?php
$true = true;
$false = false;
if($true!== $false)
{
echo "I like mango";
}else
{
echo "I like appple";
}
?>
ouput:
I like mango
Example No.4
Using string comparison
<?php
$string1 = "BMW";
$string2 = "BMW";
if($string1 == $string2)
{
echo $string1." ".$string2;
}else
{
echo "It is else";
}
?>
ouput:
BMW BMW
Saturday, 14 December 2013
if condition and concatinate in php
<?php
$variableName = "Yes";
if($variableName == "Yes")
{
echo "Your variable Name is".$variableName;
}
?>
output:
Your variable Name isYes
$variableName = "Yes";
if($variableName == "Yes")
{
echo "Your variable Name is".$variableName;
}
?>
output:
Your variable Name isYes
Simple PHP program
Php start with <?php tag and end with ?> and in the between two tags you write your code.
<?php
echo "This is my first php program";
?>
ouput:
This is my first program
<?php
echo "This is my first php program";
?>
ouput:
This is my first program
Subscribe to:
Posts (Atom)