0% found this document useful (0 votes)
7 views9 pages

PHP Program

The document contains multiple PHP programs demonstrating basic programming concepts such as printing messages, using variables, performing arithmetic and comparison operations, and working with arrays. It includes examples of indexed, associative, and multidimensional arrays, as well as sorting and counting elements in arrays. Each program is presented in HTML format with embedded PHP code for execution.

Uploaded by

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

PHP Program

The document contains multiple PHP programs demonstrating basic programming concepts such as printing messages, using variables, performing arithmetic and comparison operations, and working with arrays. It includes examples of indexed, associative, and multidimensional arrays, as well as sorting and counting elements in arrays. Each program is presented in HTML format with embedded PHP code for execution.

Uploaded by

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

1)Write a program to print message Hello world.

<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";

echo "Hello My name is ".$fname. " " .$last_name;

?>

</body>

</html>

------------------------------------------------------------------------------------------------------------------

4) Write a program to print name,class,age and marks.

<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>
------------------------------------------------------------------------

2)Get the length of an array

<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>

You might also like