PHP Program
PHP Program
<html>
<head>
<title>First Program</title>
</head>
<body>
<?php
echo "Hello world";
?>
</body>
</html>
------------------------------------------------------------------------------
2)Write a program to print multiple messages.
<html>
<head>
<title>Multiple Messages</title>
</head>
<body>
<?php
echo "Hello world <br/>";
echo "My Name is Ram <br/>";
echo "I live in pune <br/>";
echo "college of computer science <br/>";
?>
</body>
</html>
Variable:-
Syntax:-
$variable_name=value;
Example-
$name=”Nikita Deshmukh”;
$class=”SYBCA”;
$age=18;
$marks=70;
-------------------------------------------------------------------
3)Write a program to print first name and last name.
<html>
<head>
<title>Variable</title>
</head>
<body>
<?php
$fname="Ankita";
$last_name="Shrivastava";
?>
</body>
</html>
------------------------------------------------------------------------------------------------------------------
<html>
<head>
<title>Variable</title>
</head>
<body>
<?php
$name="Nikita Deshmukh";
$class="SYBCA";
$age=18;
$marks=70;
echo "My name is " .$name. " class is " .$class. " my age is " .$age. " and marks " .$marks;
?>
</body>
</html>
-------------------------------------------------------------------------------------------------------------
Calculation with Php:-
1)Arithmetic Operation-: (+,-,*,/,%)
5) Write a program for arithmetic operators.
<html>
<head>
<title>Arithmetic</title>
</head>
<body>
<?php
$a=20;
$b=15;
$c;
$c=$a+$b;
echo "Addition is: " .$c. "<br/>";
$c=$a-$b;
echo "Subtraction is: " .$c. "<br/>";
$c=$a*$b;
echo "Multiplication is: " .$c. "<br/>";
$c=$a/$b;
echo "Division is: " .$c. "<br/>";
$c=$a%$b;
echo "Modulo is: " .$c. "<br/>";
?>
</body>
</html>
Comparison operators-: (>, <,>=,<=,!=,==,===)
6) Write a program for comparison operators.
<html>
<head>
<title>Comparison</title>
</head>
<body>
<?php
$a=20;
$b=45;
$c=34;
$d=34;
if($a>$b)
echo "true <br/>";
else
echo "false <br/>";
if($a<$b)
echo "true <br/>";
else
echo "false <br/>";
if($a>=$b)
echo "true <br>";
else
echo "false <br>";
if($a<=$b)
echo "true <br>";
else
echo "false <br>";
if($c==$d)
echo "true <br>";
else
echo "false <br>";
if($c!=$d)
echo "true <br>";
else
echo "false <br>";
?>
</body>
</html>
----------------------------------------------------------------------------------------------------------------
Array-:
3 types
1)Indexed Array
2)Associative Array
3)Multidimensional Array
---------------------------------------------------------------------------
1)Array in php:-
<html>
<head>
<title>Array</title>
</head>
<body>
<?php
$name=array("Ankita","Kritika","Priyanka",56);
echo $name[0] ."<br/>";
echo $name[1] ."<br/>";
echo $name[2] ."<br/>";
echo $name[3] ."<br/>";
echo "My friend " .$name[0]. ", " .$name[1]. ", " .$name[2];
?>
</body>
</html>
------------------------------------------------------------------------
<html>
<head>
<title>Array</title>
</head>
<body>
<?php
$cars=array("BMW","Maruti","i10","Alto","Kia");
echo count($cars);
?>
</body>
</html>
-------------------------------------------------------------------------
3)Php sorting Array:-
<html>
<head>
<title>Array</title>
</head>
<body>
<?php
$cars=array("BMW","Alto","Maruti");
sort($cars);
print_r($cars) ;
rsort($cars) ;
print_r($cars);
?>
</body>
</html>
1)Indexed Array-:
<html>
<head>
<title>Indexed</title>
</head>
<body>
<?php
$name=array("Ankita","Kritika","Priyanka",40);
echo $name[0] ."<br/>";
echo $name[1] ."<br/>";
echo $name[2] ."<br/>";
echo $name[3]*2 ."<br/>";
?>
</body>
</html>
---------------------------------------------------------------------------------------------------------
2)Associative Array-:
Syntax-
$array_variable=array(“id”=>”value1”, “id”=>”value2”, “id”=>”value3”);
<html>
<head>
<title>Associative</title>
</head>
<body>
<?php
$age=array("Ram"=>14,"john"=>12,"sita"=>20);
echo $age["Ram"] ."<br/>";
echo $age["john"] ."<br/>";
echo $age["sita"] ."<br/>";
?>
</body>
</html>
----------------------------------------------------------------------------------------------------------------
3)Multidimensional Array
Syntax:-
$array_variable=array(“id”=>array(value1,value2,value3),
“id”=>array(value1,value2,value3),
“id”=>array(value1,value2,value3));
<html>
<head>
<title>Multidimensional</title>
</head>
<body>
<?php
$family=array("priya"=>array("Pooja","Neha","Ankita"),
"Surabhi" =>array("Kritika","Nidhi","Pooja"),
"Akanksha"=>array("Divya","Diksha","Nishita"));
echo $family["priya"][1]."<br/>";
echo $family["Surabhi"][2];
?>
</body>
</html>