Sei sulla pagina 1di 18

Write a program to demonstrate variable declaration in php.

<? Php

$ my string = Hello boss my name is : ;

$ my name = Amit;

$ my letter = 4 ;

echo $my string;

echo $ my name;

echo $ my letter;

?>
Write a program to demonstrate local and global variable in php.int

<? php

$ X = 4;

Function assign()

$ X = 0;

Print I$ X inside function is $ X;

assign();

print I$ X outside of function is $ X;

?>
Write a program to demonstrate function parameters in php

<? Php

Function multiply ( $ value )

$value = value * 10 ;

Return $ value;

$retval = multiply (10);

print Return value is $retval \n

?>
Write a program to adding a two numbers using parameters

<? php

$a =10;

$b = 20;

$ sum = 0 ;

$ sum = $a + $b;

Print Addition of two numbers is = $sum;

?>
Write a program to demonstrate logical operators in php

<html>

<head>

<? php

$a = 42;

$b = 0;

If ($a && $b)

echo TEST 1: Both a and b are true <br/>;

Else

echo TEST 2: Both a and b are false <br/>;

?>

</head>

</html>
Write a program to demonstrate comperigan operator in php

<html>

<head>

<title> COMPERIGAN OPERTAR </title>

</head>

<body>

<? php

$a = 42;

$b= 20;

If ($a == $b)

echo TEST 1: Both a and b are equal <br/>;

else

echo TEST 1: Both a and b are not equal <br/>;

?>

</body>

</html>
Write a program to print Have a nice Weekend! If the current day is Friday
otherwise it will output Have a nice day!

<html>

<body>

<? php

$d = date (D);

if ($d == fri)

echo Have a nice weekend ! ;

else

echo Have a nice day!;

?>

</body>

</html>
Write a program to print 1-10 Numbers for loop in php

<html>

<body>

<? php

for ( $ i=1; $i<=10; $i++)

echo ( Value of I is = $i);

?>

</body>

</html>
Write a program to print five iteration and changes the assigned value of two
variables on each pass of the loop

<html>

<body>

<? php

for ($ i=0; $i<=5; $i++)

$a + = 10 ;

$b + = 5 ;

echo ( At the end of the loop a = $a and b = $b);

?>

</body>

</html>
Write a program to print Have a nice Weekend! if the current day is Friday
and Have a nice Sunday! if the current day is Sunday otherwise it will Have
a nice day!.

<html>

<body>

<? php

$d = date (D);

if ($d == fri)

echo Have a nice weekend ! ;

else if ($d == Sun)

echo Have a nice Sunday!;

else

echo Have a nice day!;

?>

</body>

</html>
Write a program to print 1-10 numbers by using php

<html>

<body>

<? php

$i=1;

While ( $i < 10)

echo( value of i is = $ I);

$i = $1+1;

?>

</body>

</html>
Write a program to decrement the variable value on each iteration of the loop and the
counter increment until it reaches to when.

<html>

<body>

<? php

$i=0;

$sum = 50;

While ( $i < 10)

$num i

$ i++

echo ( Loop stapped of i = $i and num = $num );

?>

</body>

</html>
Write a program to array in php

<html>

<body>

<? php

/* FIRST METHOD TO CREATE ARRAY */

$ numbers = array (1,2,3,4,5);

for each ($ numbers as $value)

Echo Value is $ value </br> ;

?>

</body>

</html>
Write a program to print 1-10 numbers by using do while loop in php.

<html>

<body>

<? php

$i =1;

do

echo (Value of I is = $ I );

$ I = $ i++ ;

while ( $i<10);

?>

</body>

</html>
Write a program to list out the values of an array using in php.

<html>

<body>

<? php

$array = array(1,2,3,4,5);

for each ($ arrays as $ value)

echo Value is $ Value </br>;

?>

</body>

</html>
Write a program to the loop and print the value of array but when the condition
becomes true, it just skips the code and next value is printed

<html>

<body>

<? php

$array = array(1,2,3,4,5);

for each ($ array as $ value)

if ( $value == 3 ) continue;

echo Value is $ Value </br>;

?>

</body>

</html>
Write a program for condition test becomes true when the counter value reaches 3
and loop terminates

<html>

<body>

<? php

$i = 0;

While ($i<10)

$i++;

if ($i ==3) break;

echo(Loop Stoped at i-$i);

?>

</body>

</html>
Write a program to demonstrate string in php.

<? php

$ variable = name;

$ literally = My $ variable will not print ! \n;

print ($ literally);

$literally= My $ variable will print\n;

print ($ literally);

?>

Write a program to demonstrate strlen() function in php.

<? php

Echo strlen( Hello World! );

?>

Write a program to demonstrate strops() function in php.

<? php

Echo strops Hello World , World );

?>

Potrebbero piacerti anche