1. Declare variables for name, age, and city and display them
User Information";
echo "Name: " . $name . "
";
echo "Age: " . $age . "
";
echo "City: " . $city . "
";
?>
2. Create constants for PI and SITE_NAME and print them
Constant Values";
echo "Value of PI: " . PI . "
";
echo "Website Name: " . SITE_NAME . "
";
?>
3. Add two numbers using variables
Addition Program";
echo "First Number: $num1
";
echo "Second Number: $num2
";
echo "Sum: $sum";
?>
4. Demonstrate integer, float, string, boolean data types
PHP Data Types";
echo "Integer Value: $integerValue
";
echo "Float Value: $floatValue
";
echo "String Value: $stringValue
";
echo "Boolean Value: ";
var_dump($booleanValue);
?>
5. Swap two numbers using a temporary variable
Before Swapping";
echo "A = $a
";
echo "B = $b
";
// Using temporary variable
$temp = $a;
$a = $b;
$b = $temp;
echo "After Swapping
";
echo "A = $a
";
echo "B = $b
";
?>
6. Swap two numbers without using a temporary variable
Before Swapping";
echo "A = $a
";
echo "B = $b
";
// Swapping without temporary variable
$a = $a + $b;
$b = $a - $b;
$a = $a - $b;
echo "After Swapping
";
echo "A = $a
";
echo "B = $b
";
?>
7. Check type of a variable using gettype()
Variable Type Checking";
echo "Value: $value
";
echo "Type of Variable: " . gettype($value);
?>
8. Demonstrate arithmetic operators
Arithmetic Operators";
echo "Addition: " . ($a + $b) . "
";
echo "Subtraction: " . ($a - $b) . "
";
echo "Multiplication: " . ($a * $b) . "
";
echo "Division: " . ($a / $b) . "
";
echo "Modulus: " . ($a % $b) . "
";
?>
9. Compare two numbers using comparison operators
Comparison Operators";
echo "Num1 == Num2 : ";
var_dump($num1 == $num2);
echo "
Num1 > Num2 : ";
var_dump($num1 > $num2);
echo "
Num1 < Num2 : ";
var_dump($num1 < $num2);
?>
10. Demonstrate logical operators
Logical Operators";
echo "A AND B: ";
var_dump($a && $b);
echo "
A OR B: ";
var_dump($a || $b);
echo "
NOT A: ";
var_dump(!$a);
?>
11. Calculate area of a rectangle
Area of Rectangle";
echo "Length: $length
";
echo "Width: $width
";
echo "Area: $area";
?>
12. Calculate area of a circle
Area of Circle";
echo "Radius: $radius
";
echo "Area: $area";
?>
13. Convert Celsius to Fahrenheit
Temperature Conversion";
echo "Celsius: $celsius °C
";
echo "Fahrenheit: $fahrenheit °F";
?>
14. Increment and decrement a number
Increment and Decrement";
echo "Original Number: $number
";
$number++;
echo "After Increment: $number
";
$number--;
echo "After Decrement: $number
";
?>
15. Demonstrate assignment operators
Assignment Operators";
$value += 10;
echo "After += 10: $value
";
$value -= 5;
echo "After -= 5: $value
";
$value *= 2;
echo "After *= 2: $value
";
?>
16. Demonstrate concatenation operator
Concatenation Example";
echo "Full Name: " . $fullName;
?>
17. Display length of a string
String Length";
echo "Text: $text
";
echo "Length of String: " . strlen($text);
?>
18. Check if a variable is numeric
Numeric Check";
if(is_numeric($value)){
echo "$value is a numeric value";
}else{
echo "$value is NOT numeric";
}
?>
19. Calculate simple interest
Simple Interest Calculation";
echo "Principal: $principal
";
echo "Rate: $rate %
";
echo "Time: $time years
";
echo "Simple Interest: $simpleInterest";
?>
20. Calculate average of three numbers
Average Calculation";
echo "Number 1: $num1
";
echo "Number 2: $num2
";
echo "Number 3: $num3
";
echo "Average: $average";
?>