
PHP Code Output Quiz

Quiz
•
Computers
•
University
•
Easy
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
Similar Resources on Wayground
10 questions
Pemrograman Web

Quiz
•
University
11 questions
11 câu trắc nghiệm PHP

Quiz
•
University
7 questions
Informática VI - 3er Parcial

Quiz
•
University
10 questions
Css

Quiz
•
University
12 questions
TY A Web Technologies -II (Chapter 1 and 2) Quiz

Quiz
•
University
12 questions
Programação Web - PHP

Quiz
•
University
15 questions
Quiz Refreshment Pertemuan 2 - UMS

Quiz
•
University
15 questions
Web Dev Midterm Quiz

Quiz
•
University
Popular Resources on Wayground
18 questions
Writing Launch Day 1

Lesson
•
3rd Grade
11 questions
Hallway & Bathroom Expectations

Quiz
•
6th - 8th Grade
11 questions
Standard Response Protocol

Quiz
•
6th - 8th Grade
40 questions
Algebra Review Topics

Quiz
•
9th - 12th Grade
4 questions
Exit Ticket 7/29

Quiz
•
8th Grade
10 questions
Lab Safety Procedures and Guidelines

Interactive video
•
6th - 10th Grade
19 questions
Handbook Overview

Lesson
•
9th - 12th Grade
20 questions
Subject-Verb Agreement

Quiz
•
9th Grade