Write a PHP program to check if a person is eligible to vote

Description: Write a PHP program to check if a person is eligible to vote or not.

Rules and hints:


PHP program to check voting eligibility

<?php
function checkVote($name, $age) {
    if ($age >= 18) {
        return $name . ", you are eligible to vote.";
    }

    return $name . ", you are not eligible to vote.";
}

echo checkVote("Rakesh", 19) . "<br>";
echo checkVote("Anita", 16);
?>

Output:

Tutorials Class - Output Window

Rakesh, you are eligible to vote.
Anita, you are not eligible to vote.

How it works

  • The function gets the name and the age as parameters.
  • If the age is 18 or more it returns the eligible message, otherwise the other message.
  • We call it two times with different values.

Learn more about the similar topics:
Tutorials
PHP Decision Making
PHP match Expression
Exercises & Assignments
Write a program to check student grade based on marks
Write a program to show day of the week using switch
Write a program to calculate Electricity bill in PHP
Write a simple calculator program in PHP using switch case
Write a PHP program to check if a person is eligible to vote
Write a PHP program to check whether a number is positive, negative or zero
Write a PHP Program to print 5 to 15 using Conditional statements
Interview Questions & Answers
No Content Found.