
PHP Code Output Quiz
Authored by Karen Tan
Computers
University
Used 2+ times

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

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?
Similar Resources on Wayground
14 questions
LA5.C5: Branching and Subroutines
Quiz
•
9th Grade - University
15 questions
Python
Quiz
•
University
10 questions
DBMS 1
Quiz
•
University
15 questions
LATIHAN SOAL PEMROGRAMAN
Quiz
•
9th Grade - University
10 questions
INTRODUCCION A LA PROGRAMACION
Quiz
•
6th Grade - University
10 questions
Cybersecurity Fundamentals Week 2 Quiz
Quiz
•
KG - University
13 questions
GIT COURSE
Quiz
•
University
12 questions
UTS Semester 1 Informatika 2024/2025
Quiz
•
8th Grade - University
Popular Resources on Wayground
15 questions
Fractions on a Number Line
Quiz
•
3rd Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
22 questions
fractions
Quiz
•
3rd Grade
20 questions
Main Idea and Details
Quiz
•
5th Grade
20 questions
Context Clues
Quiz
•
6th Grade
15 questions
Equivalent Fractions
Quiz
•
4th Grade
20 questions
Figurative Language Review
Quiz
•
6th Grade