0
0
PHPprogramming~20 mins

What is PHP - Practice Questions & Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PHP Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
What is PHP primarily used for?

PHP is a popular language. What is its main use?

AManaging databases directly without a server
BDesigning the layout of web pages with styles
CWriting scripts that run only in the browser
DCreating dynamic web pages on the server side
Attempts:
2 left
💡 Hint

Think about where PHP code runs: on the server or the browser?

Predict Output
intermediate
1:30remaining
What is the output of this PHP code?

Look at this PHP code and choose the output it produces.

PHP
<?php
$number = 5;
echo $number * 2;
?>
A5
B10
CError: undefined variable
D52
Attempts:
2 left
💡 Hint

Multiplying 5 by 2 gives what number?

🔧 Debug
advanced
2:00remaining
What error does this PHP code produce?

Find the error in this PHP snippet and identify the error message.

PHP
<?php
echo 'Hello World\n';
?>
ANo error, outputs Hello World
BNotice: Undefined variable 'Hello World'
CFatal error: Call to undefined function echo()
DParse error: syntax error, unexpected end of file
Attempts:
2 left
💡 Hint

Check if all quotes and tags are properly closed.

📝 Syntax
advanced
1:30remaining
Which option correctly declares a PHP variable?

Choose the correct way to declare a variable holding the number 10 in PHP.

A$num = 10;
Bvar num = 10;
Cnum = 10;
Dlet $num = 10;
Attempts:
2 left
💡 Hint

Remember PHP variables start with a special symbol.

🚀 Application
expert
2:00remaining
What is the value of $result after running this PHP code?

Analyze the code and find the value stored in $result.

PHP
<?php
function add($a, $b = 3) {
  return $a + $b;
}
$result = add(4);
?>
AError: Missing argument for function
B4
C7
D3
Attempts:
2 left
💡 Hint

Check the default value of the second parameter.