Search Header Logo

PHP Code Output Quiz

Authored by Karen Tan

Computers

University

Used 2+ times

PHP Code Output Quiz
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

10 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

2 mins • 15 pts

What is the output of the following PHP code? class Patient { public $name; public $age; public function __construct($name, $age) { $this->name = $name; $this->age = $age; } public function getDetails() { return $this->name . " is " . $this->age . " years old."; } } $p1 = new Patient("Alice", 32); echo $p1->getDetails();

Alice is 32 years old.

Alice -> 32

Name: Alice, Age: 32

Error: Undefined method

2.

MULTIPLE CHOICE QUESTION

2 mins • 15 pts

What will the following PHP code display? function calcBMI($weight, $height) { $bmi = $weight / ($height * $height); return round($bmi, 2); } echo calcBMI(65, 1.75);

22.45

21.22

23.33

20.67

3.

MULTIPLE CHOICE QUESTION

2 mins • 15 pts

What is the output of the following code snippet? $products = ["Shoes" => 50, "Shirts" => 30, "Jeans" => 40]; function applyDiscount(&$items, $discount) { foreach ($items as $item => &$price) { $price -= ($price * $discount / 100); } } applyDiscount($products, 10); echo $products["Shoes"];

40

50

45

55

4.

MULTIPLE CHOICE QUESTION

2 mins • 15 pts

What will the code display? $inventory = [ "Product" => "Laptop", "Stock" => 15, "Price" => 75000 ]; echo json_encode($inventory);

Array (Product => Laptop, Stock => 15, Price => 75000)

Product => Laptop, Stock => 15, Price => 75000

Laptop, 15, 75000

{"Product":"Laptop","Stock":15,"Price":75000}

5.

MULTIPLE CHOICE QUESTION

2 mins • 15 pts

What will the following PHP snippet display? $students = ["John" => 85, "Alice" => 90, "Bob" => 78]; function getTopStudent($arr) { arsort($arr); return key($arr); } echo getTopStudent($students);

Alice

John

Bob

Undefined

6.

MULTIPLE CHOICE QUESTION

2 mins • 15 pts

What will be the output? class Student { public $name; public $grade; public function __construct($name, $grade) { $this->name = $name; $this->grade = $grade; } public function isPassed() { return $this->grade >= 75 ? "Passed" : "Failed"; } } $s = new Student("Emma", 72); echo $s->isPassed();

Undefined

Passed

Failed

Error

7.

MULTIPLE CHOICE QUESTION

2 mins • 15 pts

What will the following PHP code display? function calcCost($hours, $rate) { return $hours * $rate; } echo calcCost(40, 35);

1400

1350

1450

1300

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?

Discover more resources for Computers