0% found this document useful (0 votes)
53 views4 pages

PHP Program

The document outlines several PHP programs aimed at different functionalities, including checking voting eligibility based on age, counting vowels in a string, performing operations on an associative array, and calculating total marks and percentage from subject scores. Each program includes HTML forms for user input and demonstrates the use of PHP functions and decision-making statements. The document provides coding examples along with expected outputs for each aim.

Uploaded by

chawaresanket3
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)
53 views4 pages

PHP Program

The document outlines several PHP programs aimed at different functionalities, including checking voting eligibility based on age, counting vowels in a string, performing operations on an associative array, and calculating total marks and percentage from subject scores. Each program includes HTML forms for user input and demonstrates the use of PHP functions and decision-making statements. The document provides coding examples along with expected outputs for each aim.

Uploaded by

chawaresanket3
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

Aim: [SOP1]

Write a PHP program to check if a person is eligible to vote or not. The program should include
the following-

 Minimum age required for vote is 18.


 Use PHP functions.
 Use Decision making statement.

Coding:

<!DOCTYPE html>
<html>
<head>
<title>Eligible to Vote or not</title>
</head>
<body>
<form action="" method="post">
Enter a no :
<input type="text" name="t1" placeholder="Enter a number">
<br><input type="submit" name="submit" value="submit">
</form>
<?php
if (isset($_POST['submit'])) {
vote();
}
function vote() {
$a = $_POST['t1'];
intval($a);
if($a>=18){
echo "You are Eligible for Vote";
}
else{
echo "You are not Eligible for Vote";
}}
?>
</body>
</html>

Output :
Aim [SOP2]: Write a PHP function to count the total number of vowels (a,e,i,o,u) from the
string. Accept a string by using HTML form.

<html>
<body>
<h2>Find Number of Vowels in a String</h2>
<form action="" method="post">
<input type="text" name="string" />
<input type="submit" />
</form>
</body>
</html>

<?php if($_POST)

{
$string = strtolower($_POST['string']);
$vowels = array('a','e','i','o','u');
$len = strlen($string);
$num = 0;
for($i=0; $i<$len; $i++){
if(in_array($string[$i], $vowels))
{
$num++;
}
}
echo "Number of vowels : ".$num;
} ?>
Output:
Aim [SOP3]: Write a PHP program to perform the following operations on an associative
array.

 Display elements of an array along with their keys.


 Display the size of an array.
 Delete an element from an array from the given index.

Coding:

<?php
//Display elements of an array along with their keys
$age = array("Ramesh"=>"51", "Rakesh"=>"32", "RAhul"=>"23");

foreach($age as $x => $x_value) {


echo "Key = " . $x . ", Value = " . $x_value;
echo "<br>";
}
//Display the size of an array
echo "<br>Size of Array is : ".count($age)."<br>";

//Delete an element from an array from the given index


$data = array(1,2,3,4,5);
for ($i=0; $i < count($data); $i++) {
echo " ".$data[$i];
}
unset($data[1]);
echo "<br>Elements After Deleting : <br>";
for ($i=0; $i < count($data); $i++) {
echo " ".$data[$i];
}
?>

Output:
Aim [SOP4]: Write a PHP program to save marks of English, Hindi, Marathi, Maths and
Information Technology in an array. Display marks of individual subject along with total
marks and percentage

Coding:

<?php

$subject_marks = array('English' =>56 ,'Hindi' =>76,


'Marathi'=>56,'Maths' =>57 ,'IT'=>78);
$total_marks = $subject_marks['English'] +
$subject_marks['Hindi'] + $subject_marks['Marathi'] +
$subject_marks['Maths'] + $subject_marks['IT'];

echo "English : ".$subject_marks['English'];


echo "<br>Hindi : ".$subject_marks['Hindi'];
echo "<br>Marathi : ".$subject_marks['Marathi'];
echo "<br>Maths : ".$subject_marks['Maths'];
echo "<br>IT : ".$subject_marks['IT'];
echo "<br><br>Total : ".$total_marks;
$percentage = $total_marks/5;
echo "<br>Percentage : ".$percentage;
?>

Output

You might also like