Php Variables Arrays Functions Quiz
~5 minutes
MCQ Quiz
Instructions: Click an option to select your answer. Use Show Answer to reveal the correct answer at any time. When ready, click Submit Quiz to see your score.
'Ahmad']", "['age' => 20, 'city' => 'Lahore']", "['Ahmad' => 'Student']"],
"correct": 0,
"exp": "Indexed arrays use numeric keys starting from 0 to store values."
},
{
"q": "How do you define a function in PHP?",
"opts": ["function myFunction() {}", "def myFunction() {}", "func myFunction() {}", "method myFunction() {}"],
"correct": 0,
"exp": "Functions in PHP are defined using the keyword function followed by the name and parentheses."
},
{
"q": "Which operator checks equality without considering data type?",
"opts": ["==", "===", "!=", "+="],
"correct": 0,
"exp": "The == operator compares values after converting data types if needed."
},
{
"q": "What will be the output of $fruits = ['Mango', 'Apple']; echo $fruits[1];?",
"opts": ["Apple", "Mango", "0", "Error"],
"correct": 0,
"exp": "Arrays start at index 0, so $fruits[1] refers to the second element, Apple."
},
{
"q": "Which loop is commonly used to iterate through all elements of an array in PHP?",
"opts": ["foreach", "while", "do while", "switch"],
"correct": 0,
"exp": "The foreach loop is used to easily iterate over arrays without manually tracking indexes."
},
{
"q": "What is the correct way to check if a variable $balance is exactly equal to 1000 including type?",
"opts": ["$balance === 1000", "$balance == 1000", "$balance = 1000", "$balance != 1000"],
"correct": 0,
"exp": "The === operator checks both value and data type, ensuring strict equality."
},
{
"q": "Which of the following is a valid associative array in PHP?",
"opts": ["['name' => 'Fatima', 'city' => 'Karachi']", "['Mango', 'Apple']", "[0 => 'Ali', 1 => 'Ahmad']", "['Apple', 'Mango']"],
"correct": 0,
"exp": "Associative arrays use custom keys to store values, such as name => Fatima."
},
{
"q": "Which data type can hold only true or false in PHP?",
"opts": ["Boolean", "Integer", "String", "Array"],
"correct": 0,
"exp": "Boolean data type can only have two values: true or false."
},
{
"q": "What will be the output of function greet($name) { return 'Hello ' . $name; } echo greet('Ahmad');?",
"opts": ["Hello Ahmad", "Ahmad", "Hello", "Error"],
"correct": 0,
"exp": "The function concatenates Hello with the variable $name and returns Hello Ahmad."
}
]'>
0%
Your Result
0
Correct
0
Wrong
0
Skipped