wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

PHP Output Quiz2

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

What is the output of the following PHP snippet? function calcInterest($amount, $rate, $years) { return $amount * pow((1 + $rate / 100), $years); } echo calcInterest(10000, 5, 2);

a)

11025

b)

10500

c)

12000

d)

10000

2.

What will the following PHP code display? $expenses = ["Rent" => 1200, "Utilities" => 300, "Internet" => 100]; $total = array_sum($expenses); echo $total;

a)

1400

b)

1500

c)

1600

d)

1700

3.

What is the output? $clicks = [100, 250, 300, 150]; function avgClicks($arr) { return array_sum($arr) / count($arr); } echo avgClicks($clicks);

a)

250

b)

300

c)

150

d)

200

4.

What will the code display? $campaigns = [["name" => "Ad1", "clicks" => 120], ["name" => "Ad2", "clicks" => 180]]; $total = array_sum(array_column($campaigns, "clicks")); echo $total;

a)

300

b)

150

c)

120

d)

180

5.

What is the output? $parts = ["Wheels" => 40, "Doors" => 20, "Engines" => 15]; function getPartsCount($arr) { return array_sum($arr); } echo getPartsCount($parts);

a)

60

b)

65

c)

80

d)

75

6.

What is the output of the following code? class Product { public $name; public $stock; public function __construct($name, $stock) { $this->name = $name; $this->stock = $stock; } public function isAvailable() { return $this->stock > 0 ? "In stock" : "Out of stock"; } } $p = new Product("Tablet", 0); echo $p->isAvailable();

a)

Out of stock

b)

In stock

c)

Error

d)

Undefined

7.

What is the output of the following PHP snippet? $patients = [["name" => "John", "age" => 45, "status" => "Recovered"], ["name" => "Alice", "age" => 30, "status" => "In Treatment"]]; echo $patients[1]["status"];

a)

John

b)

Recovered

c)

In Treatment

d)

Undefined

8.

What will the following code display? function calcDosage($weight, $medStrength) { return $weight * $medStrength; } echo calcDosage(70, 2.5);

a)

175

b)

140

c)

180

d)

160

9.

What is the output of the following PHP code? $products = [["name" => "Shoes", "price" => 120], ["name" => "Bag", "price" => 80]]; function calcTotal($items) { $total = 0; foreach ($items as $item) { $total += $item["price"]; } return $total; } echo calcTotal($products);

a)

200

b)

150

c)

100

d)

180

10.

What will the following code display? $inventory = ["Laptops" => 15, "Phones" => 30, "Tablets" => 25]; echo count($inventory);

a)

30

b)

15

c)

25

d)

3