PHP Code Output Quiz

PHP Code Output Quiz

University

10 Qs

quiz-placeholder

Similar activities

HTML Quiz

HTML Quiz

University

10 Qs

PHP Basics

PHP Basics

University

10 Qs

CHAPTER 7 - PHP

CHAPTER 7 - PHP

University

10 Qs

PHP - Syntax & Output

PHP - Syntax & Output

University

15 Qs

PHP with MySQL quiz

PHP with MySQL quiz

University

15 Qs

PHP

PHP

University

10 Qs

PHP Introduction - Assignment 1

PHP Introduction - Assignment 1

University

10 Qs

ERD DATABASE

ERD DATABASE

University

15 Qs

PHP Code Output Quiz

PHP Code Output Quiz

Assessment

Quiz

Computers

University

Easy

Created by

Karen Tan

Used 2+ times

FREE Resource

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

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?