NEW
Font size
WorksheetsPHP Output Quiz2
Total questions: 10
Worksheet time: 5mins
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);
11025
10500
12000
10000
What will the following PHP code display? $expenses = ["Rent" => 1200, "Utilities" => 300, "Internet" => 100]; $total = array_sum($expenses); echo $total;
1400
1500
1600
1700
What is the output? $clicks = [100, 250, 300, 150]; function avgClicks($arr) { return array_sum($arr) / count($arr); } echo avgClicks($clicks);
250
300
150
200
What will the code display? $campaigns = [["name" => "Ad1", "clicks" => 120], ["name" => "Ad2", "clicks" => 180]]; $total = array_sum(array_column($campaigns, "clicks")); echo $total;
300
150
120
180
What is the output? $parts = ["Wheels" => 40, "Doors" => 20, "Engines" => 15]; function getPartsCount($arr) { return array_sum($arr); } echo getPartsCount($parts);
60
65
80
75
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();
Out of stock
In stock
Error
Undefined
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"];
John
Recovered
In Treatment
Undefined
What will the following code display? function calcDosage($weight, $medStrength) { return $weight * $medStrength; } echo calcDosage(70, 2.5);
175
140
180
160
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);
200
150
100
180
What will the following code display? $inventory = ["Laptops" => 15, "Phones" => 30, "Tablets" => 25]; echo count($inventory);
30
15
25
3
