What is the difference between $_FILES['userfile']['name'] and $_FILES['userfile']['tmp_name']?

  • name represents the original filename, while tmp_name represents the temporary location of the uploaded file
  • name represents the temporary location of the uploaded file, while tmp_name represents the original filename
  • They both refer to the same value
  • They are used for different purposes
$_FILES['userfile']['name'] represents the original filename of the uploaded file, while $_FILES['userfile']['tmp_name'] represents the temporary location where the uploaded file is stored on the server.

You are writing a PHP script and you need to store a collection of items, where each item is itself a collection of items. How would you do this using a multidimensional array?

  • Use separate arrays for each level of items.
  • Use a single array and concatenate the items as strings.
  • Use an indexed array with nested arrays for each level of items.
  • Use an associative array with numeric keys for each level of items.
To store a collection of items, where each item is itself a collection of items, you would use a multidimensional array in PHP. In this case, you can use an indexed array with nested arrays for each level of items. Each element of the outer array represents a collection, and within each element, you can have another array representing the nested collection of items. This nesting allows you to create a hierarchical structure for storing and accessing the items. With a multidimensional array, you can easily organize and manipulate complex data structures that involve multiple levels of nested items. Learn more: https://www.php.net/manual/en/language.types.array.php#language.types.array.syntax

Which function gives us the number of affected entries by a query?

  • The mysqli_affected_rows() function
  • The mysqli_num_rows() function
  • The mysqli_query_count() function
  • The mysqli_result_count() function
The mysqli_affected_rows() function is used to retrieve the number of affected rows by a query in PHP. It returns the number of rows affected by the last INSERT, UPDATE, DELETE, or REPLACE statement executed with the MySQLi connection. It's important to note that this function only works with the MySQLi extension in PHP. If you are using the deprecated MySQL extension or the PDO extension, you need to use the respective functions provided by those extensions to retrieve the number of affected rows.

If you want to read a file in PHP, you can use the fread() function where the first argument is the file pointer and the second argument is the maximum number of ______ to read.

  • lines
  • characters
  • words
  • bytes
The fread() function in PHP is used to read a file. The first argument is the file pointer obtained from fopen(), and the second argument is the maximum number of bytes to read from the file.

You need to execute a block of code in your PHP script for each key-value pair in an associative array. How would you do this using a foreach loop?

  • Use the "for" loop and access the elements using their indexes
  • Use the "foreach" loop and access the elements using the "key" and "value" variables
  • Use the "while" loop and access the elements using the "current" and "next" functions
  • Use the "foreach" loop and access the elements using the "key" and "value" pairs
The correct option is: "Use the 'foreach' loop and access the elements using the 'key' and 'value' variables." In PHP, you can use the foreach loop with an associative array to iterate over each key-value pair. During each iteration, you can access the key of the current element using the 'key' variable and the corresponding value using the 'value' variable. This allows you to execute a block of code for each key-value pair in the associative array. Learn more: https://www.php.net/manual/en/control-structures.foreach.php

What is the purpose of the fclose() function in PHP?

  • To open a file
  • To read a file
  • To write to a file
  • To close a file
The fclose() function in PHP is used to close an open file. It releases the resources associated with the file and frees up memory. It is good practice to close a file after you have finished reading from or writing to it to ensure proper cleanup and avoid resource leaks.

The $_SERVER superglobal in PHP is often used to get the URL of the current page.

  • TRUE
  • FALSE
The statement is true. By using $_SERVER['REQUEST_URI'], you can retrieve the URL of the current page. The 'REQUEST_URI' key within the $_SERVER superglobal stores the path and query string of the requested URL. This information can be useful for various purposes, such as generating dynamic navigation menus, redirecting users, or capturing analytics data. Learn more: https://www.php.net/manual/en/reserved.variables.server.php

Which of the following are valid ways to define a string in PHP?

  • 'Hello World'
  • "Hello World"
  • <<
  • All of the above
All of the given options are valid ways to define a string in PHP. Strings can be defined using single quotes (''), double quotes (""), or heredoc syntax (<<

Form Handling in PHP can involve data validation.

  • TRUE
  • FALSE
The statement is true. Form Handling in PHP often involves data validation to ensure that the user-submitted data meets the required criteria or follows specific patterns. PHP provides various functions and techniques to validate form inputs, such as checking for required fields, validating email addresses, verifying passwords, and more. By performing data validation, PHP helps maintain data integrity and enhances the security of applications by preventing the processing of erroneous or malicious inputs. Learn more: https://www.php.net/manual/en/tutorial.forms.php

In PHP, an abstract class is defined using the abstract keyword.

  • TRUE
  • FALSE
  • nan
  • nan
In PHP, an abstract class is indeed defined using the abstract keyword. This keyword is placed before the class keyword and is used to indicate that the class is intended to be an abstract class. Abstract classes are meant to be inherited by other classes and cannot be instantiated directly. Abstract classes can contain abstract methods (without implementation) as well as non-abstract methods. The abstract keyword is essential for properly defining an abstract class in PHP. For more details, refer to: http://php.net/manual/en/language.oop5.abstract.php