1. Write a php program to check whether given number is palindrome or not.
<?php
$number = 121; // change the number to test
$rev = strrev($number);
if ($number == $rev) {
echo "$number is a Palindrome Number.";
} else {
echo "$number is NOT a Palindrome Number.";
?>
2. Write a php program to check whether given number is Armstrong or not.
<?php
$number = 153; // Change the number to test
$sum = 0;
$temp = $number;
while ($temp > 0) {
$digit = $temp % 10; // Get last digit
$sum += pow($digit, 3); // Cube of the digit
$temp = (int)($temp / 10); // Remove last digit
}
if ($sum == $number) {
echo "$number is an Armstrong Number.";
} else {
echo "$number is NOT an Armstrong Number.";
?>
3. Write a php program to find largest values of two numbers using nesting of
function.
<?php
function getFirstNumber() {
return 10;
function getSecondNumber() {
return 25;
function findLargest() {
$a = getFirstNumber(); // calling first function
$b = getSecondNumber(); // calling second function
if ($a > $b) {
return "$a is the Largest Number.";
} else {
return "$b is the Largest Number.";
echo findLargest();
?>
4. Write a Mathematical calculator program.
<?php
$num1 = 20; // change numbers as needed
$num2 = 10;
$op = "*"; // + , - , * , /
switch ($op) {
case "+":
echo "Result = " . ($num1 + $num2);
break;
case "-":
echo "Result = " . ($num1 - $num2);
break;
case "*":
echo "Result = " . ($num1 * $num2);
break;
case "/":
if ($num2 == 0) {
echo "Division by zero not allowed!";
} else {
echo "Result = " . ($num1 / $num2);
break;
default:
echo "Invalid Operator!";
?>
5. Write a Age calculator program.
<?php
$birthYear = 2005;
$currentYear = date("Y");
$age = $currentYear - $birthYear;
echo "Your Age is: $age years.";
?>
6. Write a php program to check whether given number is String palindrome
or not
<?php
$str = "madam";
$rev = strrev($str);
if ($str == $rev) {
echo "$str is a String Palindrome.";
} else {
echo "$str is NOT a String Palindrome.";
?>
7. Write a php program using function.
<?php
function square($num) {
return $num * $num;
$number = 6;
echo "Square of $number is: " . square($number);
?>
8. Write a php program to Array manipulation.
<?php
$colors = array("Red", "Green", "Blue");
$colors[] = "Yellow";
unset($colors[1]); // removes "Green"
foreach ($colors as $c) {
echo $c . " ";
?>
[Link] a PHP program to validate whether the entered email address is valid or
not.
<?php
$email = "test@[Link]";
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "$email is a valid email address";
} else {
echo "$email is NOT a valid email address";
?>
10. Write a php program to check whether given number is Even or Odd
<?php
$num = 25;
if ($num % 2 == 0) {
echo "$num is an Even number";
} else {
echo "$num is an Odd number";
?>
11. Write a php program to find the factorial value
<?php
$num = 5;
$fact = 1;
for ($i = 1; $i <= $num; $i++) {
$fact = $fact * $i;
echo "Factorial of $num is: $fact";
?>
12. Write a php program to reverse a given string
<?php
$str = "Hello World";
$rev = strrev($str);
echo "Original String: $str<br>";
echo "Reversed String: $rev";
?>