Unit 1 Flashcards
What does PHP stand for today?
A. Personal Homepage Pages
B. Precompiled Hypertext Processor
C. PHP: Hypertext Preprocessor
D. Python HTML Parser
Answer: C
Which of the following statements about PHP is true?
A. PHP runs only on Windows
B. PHP is used only for desktop apps
C. PHP can be embedded within HTML
D. PHP cannot connect to databases
Answer: C
Which of the following is NOT a valid way to deploy a PHP server?
A. XAMPP on local machine
B. Azure Web Services
C. NetBeans mobile mode
D. Shared hosting with GoDaddy
Answer: C
What does the echo statement do in PHP?
A. Receives data from the user
B. Outputs data to the web browser
C. Ends a PHP script
D. Reads a file
Answer: B
Which of the following correctly outputs “Hello World!” in bold using PHP?
A. <strong><?php echo Hello World!; ?></strong>
B. <?php echo ‘<strong>Hello World!</strong>’; ?>
C. <?php echo “<b>Hello World!” ?>
D. <b><?php echo Hello World ?></b></b>
Answer: B
Which of these statements about comments in PHP is FALSE?
A. You can comment a single line using //
B. Block comments use /* */
C. PHP does not support inline comments
D. You can use comments for documentation
Answer: C
Which PHP function is used to display the current date and time?
A. getDateTime()
B. datetime_show()
C. now()
D. date()
Answer: D
What is the purpose of ., the dot operator, in PHP?
A. Multiply two strings
B. Concatenate two strings
C. Compare two values
D. End a statement
Answer: B
What does this code produce?
<?php echo date(‘l jS \of F Y h:i:s A’); ?>
~~~
A. A static string with the word “date”
B. The current time in UTC
C. A formatted current date/time string
D. The PHP version number
Answer: C
In PHPDoc, what does @param
describe?**
A. The return type of a function
B. The access level of a class
C. A variable’s value
D. The input parameter to a function
Answer: D
Which PHP function displays detailed information about the current PHP configuration?
A. php_version()
B. configInfo()
C. phpinfo()
D. showConfig()
Answer: C
When starting local development with PHP in NetBeans, which of the following is most important to have set up?
A. FTP client and domain name
B. A Java compiler
C. A local web server stack like XAMPP or WAMP
D. A Python virtual environment
Answer: C
What is the output of gettype(true) in PHP?
A. “integer”
B. “boolean”
C. “true”
D. “number”
Answer: B
What is the correct way to declare a constant named VATRATE with a value of 0.2 in PHP?
A. const VATRATE = 0.2;
B. define(VATRATE, 0.2);
C. define(‘VATRATE’, ‘0.2’);
D. $VATRATE = 0.2;
Answer: C
What is the result of this expression: (int)’10.5’?
A. 10
B. 10.5
C. 11
D. float
Answer: A
Which operator is used to concatenate two strings in PHP?
A. +
B. &
C. .
D. ++
Answer: C
Which of the following is a valid associative array in PHP?
A. $arr = array(1, 2, 3);
B. $arr = array(‘UK’, ‘FR’, ‘DE’);
C. $arr = array(‘England’ => ‘London’, ‘France’ => ‘Paris’);
D. $arr = [1, 2, 3];
Answer: C
In PHP, what does the === operator do?
A. Compares values only
B. Compares values and data types
C. Assigns values
D. Compares variable names
Answer: B
What is the difference between ++$i and $i++ in PHP?
A. One multiplies, the other divides
B. They perform different operations
C. ++$i increments before use, $i++ after
D. They are interchangeable in every case
Answer: C
Which control structure is best used when evaluating a variable against many possible fixed values?
A. if…else
B. switch
C. for
D. while
Answer: B
What is the correct syntax to declare an object of class Test and assign a value to its property?
A. $obj = new Test(); $obj.myProperty = ‘hello’;
B. $obj = new Test(); $obj->myProperty = ‘hello’;
C. Test obj = new(); obj->myProperty = ‘hello’;
D. $obj = Test(); $obj->myProperty = ‘hello’;
Answer: B
Which built-in function returns both key and value from an array?
A. get()
B. foreach()
C. print_r()
D. var_dump()
Answer: B (in context of looping)
Which operator would evaluate TRUE only if either $a or $b is TRUE, but not both?
A. &&
B. or
C. xor
D. ==
Answer: C
Which of the following functions returns the structure and types of a variable in PHP?
A. show()
B. print_r()
C. var_dump()
D. debug()
Answer: C
What is a Heredoc in PHP used for?
A. Looping over objects
B. Running SQL queries
C. Outputting large multiline strings
D. Creating comments
Answer: C
What function would you use to calculate the average of a numeric array in PHP (using built-in functions)?
A. mean($array)
B. avg($array)
C. array_sum($array) / count($array)
D. sum($array)
Answer: C
What keyword allows a function to send a value back to the caller?
A. return
B. break
C. output
D. yield
Answer: A
What will isset($var) return if $var = null;?
A. true
B. false
C. null
D. It will throw an error
Answer: B
What is the output of this code?
$a = 5;
$b = &$a;
$a = 10;
echo $b;
~~~
A. 5
B. 10
C. 0
D. Error: invalid reference
Answer: B
Explanation: $b
is a reference to $a
, so it reflects the updated value of $a
You want to generate the first n
rows of Floyd’s Triangle in PHP. What control structure is best suited for this task?
A. foreach
B. if
C. Nested for
loops
D. switch
Answer: C