1. What actual underlying values are represented by TRUE and FALSE?
In PHP, TRUE represents the value 1 and FALSE represents NULL, which can be thought of as ‘nothing’ and is output as the empty string.
2. What are the simplest two forms of expressions?
The simplest forms of expressions are literals (such as numbers nd strings) and variables, which simply evaluate to themselves.
3. What is the difference between unary, binary, and ternary operatoers?
The difference between unary, binary, and ternary operators is the number of operands each requires (one, two, and three, respectively).
4. What is the best way to force your own operator precedence?
The best way to force your own operator precedence is to place parentheses around is to place parentheses around subexpressions to which you wish to give high precedence.
5. What is meant by operator associativity?
Operator associativity refers to the direction of processing (left to right or right to left).
6. When would you use the === (identity) operator?
You use the identity operator when you wish to bypass PHP’s automatic operand type changing (also callled type casting).
7. Name the three conditional statement types.
The three conditional statement types are if, switch, and the ? operator.
8. What command can you use to skip the current iteration of a loop and move on to the next one?
To skip the current iteration of a loop and move on to the next one, use a continue statement.
9. Why is a for loop more powerful than a while loop?
Loops using for statements are more powerful than while loops because they support two additional parameters to control the loop handling.
10. How do if and while statements interpret conditional expressions of different data types?
Most conditional expressions in if and while statements are literal (or Boolean) and therefore trigger execution when they evaluate to TRUE. Numeric expressions trigger execution when they evaluate to a nonzero value. String expressions trigger execution when they evaluate to a nonempty string. A NULL value is evaluated as false and therefore does not trigger execution.
1. What is the main benefit of using a function?
Using a functions avoids the need to copy or rewrite similar code sections many times over by combining sets of statements together so that they can be called by a simple name.
2. How many values can a function return?
By default, a function can return a single value. But by utilizing arrays, references, and global variables, any number of values can be returned.
3. What is the difference between accessing a variable by name and by reference?
When you reference a variable by name, such as by assigning its value to another variable or by passing its value to a function, its value is copied. The original does not change when the copy is changed. But if you reference a value, only a pointer (or reference) to its value is used, so that a single value is referenced by more than one name. Changing the value of the reference will change the original as well.
4. What is the meaning of scope in PHP?
Scope refers to which parts of a program can access a variable. For example, a variable of global scope can be accessed by all parts of a PHP program.
5. How can you incorporate one PHP file within another?
To incorporate one file within another, you can use the include or require directives, or their safer variants, include_once and require_once.
6. How is an object different from a function?
A function is a set of statements referenced by a name that can receive and return values. An object may contain zero, one, or many functions (which are then called methods) as well as variables (which are called properties), all combined in a single unit.
7. How do you create a new object in PHP?
To creat a new object in PHP, use the new keyword like this:
$object = new Class
8. What syntax would you use to create a subclass from an existing one?
To create a subclass, use the extends keyword with syntax such as this: class Subclass extends Parentclass.
9. Who can you call an initializing piece of code when an object is created?
To call a piece of initializing code when an object is created, create a constructor method called __construct within the class and place your code there.
10. Why is it a good idea to explicitly declare properties within a class?
Explicitly decaring properties within a class is unnecessary, as they will be implicitly declared upon first use. However, it is considered good practice as it helps with code readability and debugging, and is especially useful to other people who may have to maintain your code.
1. What is the difference between a numeric and an associative array?
A numeric array can be indexed numerically using numbers or numeric variables. An associative array uses alphanumeric identifiers to index elements.
2. What is the main benefit of the array keyword?
The main benefit of the array keyword is that it enables you to assign several values at a time to an array without repeating the array name.
3. What is the difference between foreach and each?
Both the each function and the foreach … as loop construct return elements from an array; both start at the beginning and increment a pointer to make sure the next element is returned each time, and both return FALSE when the end of the array is reached. The difference is that the each function returns just a single element, so it is usually wrapped in a loop. Thr foreach … as construct is already a loop, executing repeatedly until the array is exhausted or you explicitly break out of the loop.
4. How can you create a multidimensional array?
To create a multidimensional array, you need to assign additional arrays to elements of the main array.
5. How can you determine the number of elements in an array?
You can use the count function to count the number of elements in an array.
6. What is the purpose of the explode function?
The purpose of the explode function is to extract sections from a string that are separated by an identifier, such as extracting words separated by spaces within a sentence.
7. How can you set PHP’s internal pointer into an array back to the first element of the array?
To reset PHP’s internal pointer into an array back to the first element, call the reset function.
1. Which printf conversion specifier would you use to display a floating-point number?
The conversion specifier you would use to display a floating-point number is %f.
2. What printf statement could be used to take the input string “Happy Birthday” and output the string “**Happy”?
To take the input string “Happy Birthday” and out the string “**Happy”, you could use a printf statement such as
printf ("%'*7.5s", "Happy Birthday");
3. To send the output from printf to a variable instead of to a browser, what alternative function would you use?
To send the output from printf to a variable instead of to a browser, you would use sprintf instead.
4. How would you create a Unix timestamp for 7:11 AM on May 2, 2016?
To create a Unix timestamp for &:11 AM on May 2, 2016, you could use the command
$timestamp = mktime (7, 11, 0, 5, 2, 2016);
5. Which file access mode would you use with fopen to open a file in write and read mode, with the file truncated and the file pointer at the start?
You would use the w+ file access mode with fopen to open a file in write and read mode, with the file truncated and the file pointer at the start.
6. What is the PHP command for deleting the file file.txt?
THe PHP command for deleting the file file.txt is
7. Which PHP function is used to read in an entire file in one go, even from across the Web?
The PHP function file_get_contents is used to read in an entire file in one go. It will also read a file from across the Internet if provided with a URL.
8. WHich PHP system variable holds the details on uploaded files?
The PHP associative array $_FILES contains the details about uploaded files.
9. Which PHP function enables the running of system commands?
The PHP exec function enables the running of system commands.
10. What is wrong with the following XHTML 1.0 tag:
In XHTML 1.0, the tag
should be replaced with the following syntax:
All parameters must be quoted, and tags without closing tags must be self-closed using />.