PHP PHP Syntax & Core Language Features 1 — Questions and Answers
Question 1: Which symbol is used to prefix all variable names in PHP?
- $ (Correct answer)
- @
- #
- &
Correct answer: $
In PHP, all variable names must begin with a dollar sign ($), such as $name or $count.
Question 2: Which PHP construct is used to output text directly to the browser?
- print_r()
- var_dump()
- echo (Correct answer)
- return
Correct answer: echo
echo is a language construct in PHP used to output one or more strings to the browser.
Question 3: What character is used to end a PHP statement?
- :
- .
- ; (Correct answer)
- ,
Correct answer: ;
PHP statements must end with a semicolon (;), similar to C and Java.
Question 4: Which superglobal array holds data submitted via an HTML form using GET?
- $_POST
- $_REQUEST
- $_SERVER
- $_GET (Correct answer)
Correct answer: $_GET
$_GET is the PHP superglobal that contains all URL query string parameters passed via GET requests.
Question 5: What does the isset() function check in PHP?
- If a variable is an integer
- If a variable is set and not NULL (Correct answer)
- If a variable equals zero
- If a variable is a string
Correct answer: If a variable is set and not NULL
isset() returns true if the variable exists and its value is not NULL.
Question 6: Which operator is used to concatenate two strings in PHP?
- +
- &&
- . (Correct answer)
- ::
Correct answer: .
PHP uses the dot (.) operator to concatenate strings, unlike JavaScript which uses +.
Which symbol is used to prefix all variable names in PHP?