PHP Flashcards
PHP can be run without a server.
False.
Who originally authored PHP, and when?
Rasmus Lerdorf, in 1994.
PHP is an open source product.
True.
PHP is a client-side scripting language whose scripts are embedded in HTML documents.
False, PHP is a server-side scripting language.
Is PHP statically or dynamically typed?
Dynamic.
PHP is purely interpreted, meaning what?
PHP is executed directly by the interpreter without being compiled into machine code first.
In what version of PHP was OOP functionality first added?
PHP 3.
In what version of PHP was object handling completely rewritten?
PHP 5.
How is internal PHP code embedded in HTML documents?
By inserting the code between the “<?php” and “?>” tags.
How is external PHP code embedded in HTML documents?
<?php include(“script.php”); ?>
What are the three ways of writing comments in PHP?
…
//…, #…, or /* … */
PHP variable names must always be preceded by a ‘$’.
True.
The following unassigned (unbound) variable has what value?
$x;
Null.
The following are both valid print methods:
print “Hello World! < br >”;
echo “Hello World! < br >”;
True.
The following are both valid print methods:
print (“Hello World! < br >”);
echo (“Hello World! < br >”);
True.
The following will print the value stored in $x:
echo “The value is: $x”;
True.
The following will print the value stored in $x:
echo “The value is: “ + $x;
False - this will print ‘0’, as the compiler attempts a numerical addition.
The following will print the value stored in $x:
echo “The value is: “.$x;
True.
The following will print the value stored in $x:
echo “The value is: “, $x;
True.
How many primitive types are there in PHP?
8.
What are the 3 categories of primitive types in PHP?
Scalar types, compound types, and special types.
What are the 4 (primitive) scalar types in PHP?
Boolean, Integer, Double, String.
What are the 2 (primitive) compound types in PHP?
Array and Object.
What are the 2 (primitive) special types in PHP?
Resource and NULL.
7E2 and 7e2 are both valid numeric literals in PHP.
True.
7,000 and 7,000,000 are both valid numeric literals in PHP.
False, neither are.
7.2E-2 is a valid numeric literal in PHP.
True.
0x0A and 0X0A are both valid numeric literals in PHP.
True.
By default, how many bytes per character in PHP?
1
The native PHP string is “Unicoded” (outputted as a Unicode string).
False.
You cannot output a Unicode string in PHP.
False - you can.
What character is used to delimit String literals in PHP?
Either single or double quotes.
What is the difference between single and double quote delimiters for string literals in PHP?
They do not allow the same substitutions.
What will be printed to the html document?
echo ‘he\’s cool \n’;
he’s cool \n
What will be printed to the html document?
$x = ‘me’;
echo ‘he\’s “cool\” like $x’;
he’s “cool\” like $x
What will be printed to the html document?
echo “he\’s cool \n”;
he\’s cool
What will be printed to the html document?
$x = ‘me’;
echo “he\’s \“cool\” like $x”;
he\’s “cool” like me
What will be displayed on the browser?
$sum = 100;
print(‘The sum is $sum <br> Is that ok?’);
The sum is $sum
Is that ok?
The following will result in how many empty lines between characters ‘a’ and ‘b’?
print(“a\n”);
print(“<br>”);
print(“b\n”);
0
What is the output of the following code on the browser?
$a = “Guns N\’ Roses”;
print(“\$a”);
$a
Boolean values in PHP are case senstive.
False.
In PHP, 0 and 0.0 evaluate to Boolean false.
True.
In PHP, both “” and NULL evaluate to Boolean false.
True.
In PHP, “0” evaluates to Boolean false.
True.
In PHP, ‘0’ evaluates to Boolean false.
True.
The following code sets $x’s value to what?
unset($x);
NULL.
When does the following expression return true?
isset($x);
When $x’s value isn’t NULL.
NULL is coerced to 0 if the context specifies a number.
True.
NULL is coerced to “null” if the context specifies a string.
False - it is coerced to an empty string.
What is phpinfo()?
phpinfo() is a predefined function that outputs information about the PHP configuration and environment.
What does round(5.5) return?
6
What does PHP’s built in srand() function do?
srand() seeds a random number generator. There is no reason to do this past PHP 4.2.0.
What does rand() return if we don’t pass any arguments?
Nothing, rand() requires 2 arguments.
Which PHP function rounds doubles up, and which rounds down?
ceil() and floor().
Which php function returns the absolute value of a number?
abs()
Which PHP functions return the smallest/greatest values out of a list of values?
min() and max()
What operator is used in PHP for string concatenation?
.
Can commas be used for string concatenation?
No, but echo can take multiple arguments separated by commas.
The second line exhibits a valid method of concatenation.
$a = “Hello “;
$a .= “World!”
True.
What does strlen($str) return?
The length of $str.
What does strcmp($str1, $str2) return?
0 if the strings are identical, a negative number if the first string “comes” before the second (in the ASCII sequence) and a positive number if the second string comes before the first.
What does strpos($str1, $str2) return?
The character position of $str2’s position in $str1, if it exists.
What does substr($str, $int) return?
The substring of $str, from index $int to the end.
What does chop($str) return?
$str but will all whitespace removed from its end.
What does trim($str) return?
$str but will all whitespace removed from both ends.
What does ltrim($str) return?
$str but will all whitespace removed from its beginning.
What does strtolower($str) return?
$str in all lowercase.
What does strtoupper($str) return?
$str in all uppercase.
what does the following code output?
echo substr(“Apples are good”, 7, 2);
ar
what does the following code output?
echo strcmp(‘a’, ‘c’);
-2
What does strpos($str1, $str2) return if $str2 isn’t found in $str1? (PHP)
False.
What does the following code output?
$str = ‘Look at the sea’;
$str[strlen($str)-1] = ‘e’;
echo $str;
Look at the see
What is the output of the following code?
$x = “hi”[1];
echo $x;
i
In PHP, how many ways are there to explicitly convert (cast) a value?
3
Write 3 ways to cast the value in $x to an integer in PHP.
(int) $x
intval($x)
settype($x, “integer”)
How many ways are there to determine the type of a variable in PHP? What are they?
2 - gettype($x) or is_integer($x).
gettype($x) returns what if $x’s type can’t be determined?
“unknown”
When can a string be converted (or coerced) to an integer? (PHP)
If it begins with an integer.
In PHP, when can a string be converted (or coerced) to a double? (4 cases)
If the string begins with a double, a period, an e or an E.
If a PHP string does not begin with a sign or a digit, then what number is it implicitly converted (coerced) to?
0
What is NULL coerced to if the context specifies a number?
0
What is NULL coerced to if the context specifies a string?
”” (empty string)
What is the output of the following?
$str = ‘5.1’;
print($str+1);
6.1
What is the output of the following?
$str = ‘5.1’;
print((int)$str);
5