Roll No 042 PHP Assignment
Roll No 042 PHP Assignment
<?php
$rows = 7;
$cols = 6;
echo "*";
else
echo "<br>";
?>
output:
*****
* *
* *
*****
2. Write a PHP script that creates the following table (use for loops).
1 2 3 4 5 6 7 8 9 10
2 4 6 8 10 12 14 16 18 20
3 6 9 12 15 18 21 24 27 30
4 8 12 16 20 24 28 32 36 40
5 10 15 20 25 30 35 40 45 50
6 12 18 24 30 36 42 48 54 60
7 14 21 28 35 42 49 56 63 70
8 16 24 32 40 48 56 64 72 80
9 18 27 36 45 54 63 72 81 90
10 20 30 40 50 60 70 80 90 100
<?php
$rows = 10;
$cols = 10;
$value = $i * $j;
?>
3. Write a PHP script to remove nonnumeric characters except comma and dot.
<?php
// Sample string
$sample_string = '$123,34.00A';
echo $cleaned_string;
?>
4. Write a PHP program to check which number nearest to the value 100 among two given
integers. Return 0
Sample Input:
78, 95
95, 95
99, 70
Sample Output:
95
99
<?php
$target = 100;
if ($diff1 == $diff2) {
} else {
// Sample Input
$input = array(
array(78, 95),
array(95, 95),
array(99, 70)
);
?>
5. Write a PHP program to create a new array from a given array of integers shifting all zeros
to left direction.
Sample Input:
{ 1, 2, 0, 3, 5, 7, 0, 9, 11 }
Sample Output:
<?php
function shiftZerosToLeft($arr) {
$n = count($arr);
$result = array_fill(0, $n, 0); // Create an array of zeros with the same size as $arr
if ($arr[$i] != 0) {
$result[$index++] = $arr[$i];
return $result;
$newArray = shiftZerosToLeft($input);
?>
6. Write a PHP class called 'Vehicle' with properties like 'brand', 'model', and 'year'.
Implement a method to
<?php
class Vehicle {
// Properties
public $brand;
public $model;
public $year;
// Constructor
$this->brand = $brand;
$this->model = $model;
$this->year = $year;
// Example usage
$vehicle1->displayDetails();
// You can create more instances and display their details as needed
?>
7. Write a PHP class called 'Student' with properties like 'name', 'age', and 'grade'. Implement
a method to
<?php
class Student {
// Properties
public $name;
public $age;
public $grade;
// Constructor
$this->name = $name;
$this->age = $age;
$this->grade = $grade;
}
// Example usage
$student1->displayInformation();
// You can create more instances and display their information as needed
?>