Wednesday, April 26, 2017

Freelancer Exams Questions & Answers: PHP Level 1 - PART II

PHP Level 1 Exam


1. What is the correct way to add 1 to the $counter variable?

Answer: $counter++;

2. What function raises the first argument to the power of the second argument, with decimal places to be specified by the scale factor?

Answer: bcpow();

Example:
 <?php echo bcpow('4.2''3'2); // 74.08 ?>

3. Which operator performs the same function as x=x%y?
Answer: %=

Example
<?php

$x = 9;
$y = 4;

echo $x%$y;  // output is: 1

echo $x %= $y; // output is: 1

?>

4. Which file mode will read and write to the end of an existing file or create a new file?
Answer: w+

Basic file modes
rRead only. Starts at the beginning of the file
r+Read/Write. Starts at the beginning of the file
wWrite only. Opens and clears the contents of file; or creates a new file if it doesn't exist
w+Read/Write. Opens and clears the contents of file; or creates a new file if it doesn't exist
aAppend. Opens and writes to the end of the file or creates a new file if it doesn't exist
a+Read/Append. Preserves file content by writing to the end of the file
xWrite only. Creates a new file. Returns FALSE and an error if file already exists
x+Read/Write. Creates a new file. Returns FALSE and an error if file already exists


5. Which of the following is correct for adding a comment in a PHP script?
Answer: /* comment */

Type of comments in PHP
 //   or  #   single line comment
/* */            multi line  comment


6. Which function returns (and caches) the owner ID number?
Answer: fileowner()

7. Which of the following is the correct way to implement a do-while loop?
Answer:  
$j = 0; 
do { print "$j"; } 
while ($j > 0);

8. Which statement will skip the rest of the current loop iteration and continue execution at the beginning of next iteration.

Answer: continue

9. Which of the following is correct to show a message for an exception?
Answer: throw new Exception ("Invalid data");

Example
<?php

function inverse($x) {
    if (!$x) {
        throw new Exception('Division by zero.');
    }
    return 1/$x;
}
?>


10. What term refers to the ability to shorten Extra_Long_Names improving readability of source code? 
Answer: Aliasing 

11. What PHP function returns the arctangent in radians of a numerical argument?
Answer: atan()

12.Which function is used to start tracking a user?
Answer: session_start()

13. What statement will delete session files?
Answer: session_destroy()

14. How are sessions tracked on PHP
Answer: with code rewriting using the PHP Session reference variable

15. The file handle argument in fread() allows you to specify ___________.
Answer: the number of bytes you wish to read


PHP Level 1 Exam

1. What is the correct way to add 1 to the $counter variable?
Answer: $counter++;

2. What function raises the first argument to the power of the second argument, with decimal places to be specified by the scale factor?
Answer: bcpow();

 

3. Which operator performs the same function as x=x%y?
Answer: %=

4. Which file mode will read and write to the end of an existing file or create a new file?
Answer: w+

Basic file modes 
r
Read only. Starts at the beginning of the file
r+
Read/Write. Starts at the beginning of the file
w
Write only. Opens and clears the contents of file; or creates a new file if it doesn't exist
w+
Read/Write. Opens and clears the contents of file; or creates a new file if it doesn't exist
a
Append. Opens and writes to the end of the file or creates a new file if it doesn't exist
a+
Read/Append. Preserves file content by writing to the end of the file
x
Write only. Creates a new file. Returns FALSE and an error if file already exists
x+
Read/Write. Creates a new file. Returns FALSE and an error if file already exists


5. Which of the following is correct for adding a comment in a PHP script?
Answer: /* comment */

Type of comments in PHP
 //   or  #   single line comment
/* */            multi line  comment


6. Which function returns (and caches) the owner ID number?
Answer: fileowner()

7. Which of the following is the correct way to implement a do-while loop?
Answer:
$j = 0;
do { print "$j"; }
while ($j > 0);
 


8. Which statement will skip the rest of the current loop iteration and continue execution at the beginning of next iteration.
Answer: continue

9. Which of the following is correct to show a message for an exception?
Answer: throw new Exception ("Invalid data"); 


10. What term refers to the ability to shorten Extra_Long_Names improving readability of source code? 
Answer: Aliasing 

11. What PHP function returns the arctangent in radians of a numerical argument?
Answer: atan()

12.Which function is used to start tracking a user?
Answer: session_start()

13. What statement will delete session files?
Answer: session_destroy()

14. How are sessions tracked on PHP
Answer: with code rewriting using the PHP Session reference variable 


15. The file handle argument in fread() allows you to specify ___________.
Answer: the number of bytes you wish to read

No comments:

Post a Comment

lEARNING: SQL | WHERE Clause

SQL | WHERE Clause WHERE keyword is used for fetching filtered data in a result set. It is used to fetch data accord...