0% found this document useful (0 votes)
15 views

php_prac_1

This document contains a series of practical PHP programming exercises demonstrating various concepts such as printing strings, using arithmetic, increment/decrement, comparison, data types, arrays, string and array operators, conditional operators, the spaceship operator, and bitwise operators. Each exercise includes PHP code snippets along with expected outputs. The document serves as a guide for beginners to understand and implement basic PHP functionalities.

Uploaded by

saeedarwatkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

php_prac_1

This document contains a series of practical PHP programming exercises demonstrating various concepts such as printing strings, using arithmetic, increment/decrement, comparison, data types, arrays, string and array operators, conditional operators, the spaceship operator, and bitwise operators. Each exercise includes PHP code snippets along with expected outputs. The document serves as a guide for beginners to understand and implement basic PHP functionalities.

Uploaded by

saeedarwatkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Practical No.

1
1) Write a program to print “Welcome to PHP”
<?php

echo "<h1><b>Welcome to PHP</b></h1>";

?>

Output:

2) Write a simple PHP program using Arithmetic operators.


<?php

$a=10;

$b=5;

echo "--Arithmetic Operators--";

echo "<br>";

echo "The value of Number 1:".$a;

echo "<br>";

echo "The value of Number 2:".$b;

echo "<br>";

echo "Addition is: ".$a+$b;


echo "<br>";

echo "Subtraction is: ".$a-$b;

echo "<br>";

echo "Multiplication is: ".$a*$b;

echo "<br>";

echo "Division is: ".$a/$b;

echo "<br>";

echo "Modulus is: ".$a%$b;

echo "<br>";

echo "Exponentiation is: ".$a**$b;

?>

Output:
3) Write a simple PHP program using Increment and Decrement operators.

<?php

$x=5;

echo "Pre-Increment: ".++$x ;

echo "<br>";

echo "Post-Increment: ".$x++;

echo "<br>";

echo "Pre-Decrement: ".--$x;

echo "<br>";

echo "Post-Decrement: ".$x--;

echo "<br>";

?>

Output:
4) Write a simple PHP Program using Comparison operators.
<?php

$x=10;

$y="10";

echo "Equal:".

var_dump($x==$y);

echo "<br>";

echo "Identical: ";

var_dump($x===$y) ;

echo "<br>";

echo "Not equal: ";

var_dump($x!=$y);

echo "<br>";

echo "Not equal: ";

var_dump($x<>$y) ;

echo "<br>";

echo "Not identical: ";

var_dump($x!==$y) ;

echo "<br>";

echo "Greater than: ";

var_dump($x>$y);

echo "<br>";

echo "Less than: ";

var_dump($x<$y) ;

echo "<br>";

echo "Greater than or equal to: ";

var_dump($x>=$y);

?>
Output :
5) Write a Program to implement Datatypes in PHP.
<?php

$a=10;

$b=10.5;

$c="Hello";

$d=true;

var_dump($a);

echo "<br>";

var_dump($b);

echo "<br>";

var_dump($c);

echo "<br>";

var_dump($d);

?>

Output:
6) Write a program to implement Array in PHP.
<?php

$a = array(10,20,30);

echo "$a[0]";

echo "<br>";

echo "$a[1]";

echo "<br>";

echo "$a[2]";

echo "<br>";

print_r($a);

?>

Output:
7) Write a program to implement String operators.
<?php

$a="Saee";

$b="Darwatkar";

$c=$a.$b;

echo "$c <br>";

$a.=" TYCM ";

echo "$a <br>";

?>

Output:
8) Write a program to implement Array Operators.
<?php

$a=array('a'=>'C','b'=>'Java','c'=>'Pyhton');

$b=array('d'=>'Perl','e'=>'PHP','f'=>'Javascript');

var_dump($a+$b);

echo "<br>";

var_dump($a==$b);

echo "<br>";

var_dump($a!=$b);

echo "<br>";

var_dump($a===$b);

echo "<br>";

var_dump($a!==$b);

echo "<br>";

?>

Output:
9) Write a program to implement Conditional Operator.
<?php

$a=10;

$b=15;

$x=($a>$b)?$a:$b;

echo "Largest Number: $x";

?>

Output:
10) Write a program to implement Spaceship Operator.
<?php

$x=5;

$y=10;

echo($x<=>$y);

echo "<br>";

$x=10;

$y=10;

echo($x<=>$y);

echo "<br>";

$x=15;

$y=10;

echo($x<=>$y);

echo "<br>";

?>

Output:
11) Write a program to implement Bitwise operator.
<?php

$a = 5;

$b = 3;

$ans = $a & $b;

echo("Bitwise & of 5 and 3 is $ans");

echo "<br>";

$ans = $a | $b;

echo("Bitwise | of 5 and 3 is $ans");

echo "<br>";

$ans = $a ^ $b;

echo("Bitwise ^ of 5 and 3 is $ans");

echo "<br>";

$ans = ~$a;

echo("Bitwise ~ of 5 is $ans");

echo "<br>";

$b = 1;

$ans = $a << $b;

echo("5 << 1 will be $ans");

echo "<br>";

$ans = $a >> $b;

echo("5 >> 1 will be $ans");

echo "<br>";

?>
Output:

You might also like