Untitled Document (10)
Untitled Document (10)
<?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";?>
<?php
for ($i = 1; $i <= 10; $i++) {
if ($i % 2 == 0) {
echo "$i is even\n";
} else {
echo "$i is odd\n";
}
}
?>
<?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
<?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);
?>