0% found this document useful (0 votes)
2 views

Untitled Document (10)

The document contains multiple PHP programs demonstrating various programming concepts such as using switch statements for a calendar program, logical operators, loops, and different types of arrays (indexed, associative, and multidimensional). Each program is clearly structured with comments and outputs relevant information based on user input or predefined data. The examples illustrate fundamental programming techniques suitable for beginners.

Uploaded by

sanskrutinile06
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)
2 views

Untitled Document (10)

The document contains multiple PHP programs demonstrating various programming concepts such as using switch statements for a calendar program, logical operators, loops, and different types of arrays (indexed, associative, and multidimensional). Each program is clearly structured with comments and outputs relevant information based on user input or predefined data. The examples illustrate fundamental programming techniques suitable for beginners.

Uploaded by

sanskrutinile06
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/ 5

3.Write a calendar program using switch statement.

<?php
$month = (int)readline("Enter the month number (1-12): ");
$year = (int)readline("Enter the year: ");
switch ($month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
$days = 31;
break;
case 4:
case 6:
case 9:
case 11:
$days = 30;
break;
case 2:
if (($year % 4 == 0 && $year % 100 != 0) || ($year % 400 == 0)) {
$days = 29;
} else {
$days = 28;
}
break;
default:
echo "Invalid month entered.\n";exit;
}echo "Month $month of year $year has $days days.\n";?>

4. Write a program to make the use of logical operators.


<?php
$a = (int)readline("Enter the first number: ");
$b = (int)readline("Enter the second number: ");
if ($a > 0 && $b > 0) {
echo "Both numbers are positive.";
} elseif ($a > 0 || $b > 0) {
echo"At least one number is positive";
} else {
echo "Both numbers are non-positive.\n";
}
?>
Practical3

1.Write a program to print first 30 even numbers.


<?php
for ($i = 1; $i <= 30; $i++) {
echo $i * 2 . "\n";
}
?>
2.Write any program using if condition with for loop

<?php
for ($i = 1; $i <= 10; $i++) {
if ($i % 2 == 0) {
echo "$i is even\n";
} else {
echo "$i is odd\n";
}
}
?>

3.Write a program to display pyramids of star/patterns using increment/decrement.

<?php
$rows = 5;
for ($i = 1; $i <= $rows; $i++) {
for ($j = $i; $j < $rows; $j++) {
echo " ";
}
$stars = 2 * $i - 1;
echo str_pad("", $stars, "*") . "\n";
}
?>
Practical4

1.Develop a program to using Indexed array.


<?php
$city = array(0 => "Pune", 1 => "Mumbai", 2 => "Delhi", 3 => "Chennai");
echo "Printing the entire array: <br>";
for ($i = 0; $i < count($city); $i++) {
echo "Index $i: " . $city[$i] . "<br>";
}
echo "<br>Alternatively, printing the array using print_r():<br>";
print_r($city);
?>

2.Develop a program to using Associative array


<?php
$city = array(
"Mumbai" => "India",
"Paris" => "France",
"London" => "England",
"New York" => "USA",
"Tokyo" => "Japan",
"Rome" => "Italy",
"Rio de Janeiro" => "Brazil");
echo "Printing the associative array:<br>";
foreach ($city as $cityName => $country) {
echo "City: $cityName, Country: $country<br>";}
echo "<br>Alternatively, printing the array using print_r():<br>";
print_r($city);
?>

3.Develop a program to using Multidimensional array.

<?php
$students = array(
"Alice" => array("Math" => 85, "Science" => 92, "English" => 88),
"Bob" => array("Math" => 78, "Science" => 81, "English" => 74),
);
echo "Student Marks Information:<br>";
foreach ($students as $studentName => $subjects) {
echo "<strong>Student: $studentName</strong><br>";
foreach ($subjects as $subject => $marks) {
echo "$subject: $marks<br>";
}
echo "<br>";
}
echo "<br>Alternatively, printing the multidimensional array using print_r():<br>";
print_r($students);
?>

You might also like