What function do you use in PHP to establish an FTP connection?

  • ftp_connect()
  • file_get_contents()
  • mysqli_connect()
  • All of the above
To establish an FTP connection in PHP, you can use the ftp_connect() function with the FTP server hostname, username, and password as parameters. For example, $connection = ftp_connect($ftpServer, $ftpUsername, $ftpPassword); establishes an FTP connection to the specified server using the provided credentials and returns a connection resource. This resource is then used in subsequent FTP operations such as file transfers or directory listings. The ftp_connect() function is a fundamental function for establishing FTP connections in PHP.

How do you close a connection to a MySQL database in PHP?

  • Using the mysqli_close() function
  • Using the mysql_close() function
  • Using the pdo_close() function
  • Using the database_close() function
To close a connection to a MySQL database in PHP, you can use the mysqli_close() function. This function takes the MySQLi object representing the database connection as a parameter and closes the connection. It is important to explicitly close the database connection when you're done with it to free up resources. However, PHP automatically closes the connection at the end of the script execution, so it is not always necessary to explicitly close the connection, but it's good practice to do so.

Which of the following are true about the else statement in PHP?

  • It provides an alternative code block to be executed when the preceding if condition is false
  • It can only be used without an if statement
  • It can be used multiple times within the same code block
  • It can test multiple conditions
The else statement in PHP provides an alternative code block to be executed when the preceding if condition is false. It is used in conjunction with an if statement and allows you to specify a different set of instructions to be executed when the initial condition is not true. The else statement can only be used after an if statement, and there can be only one else statement corresponding to each if statement. It cannot be used without an if statement. The else statement provides flexibility in controlling the flow of execution based on different conditions. Learn more: https://www.php.net/manual/en/control-structures.else.php

In PHP file upload, the $_FILES array contains keys like 'name', 'type', 'size', 'tmp_name', and 'error' which represent ______.

  • various attributes of the uploaded file
  • form field names
  • server configuration settings
  • session information
In PHP file upload, the $_FILES array contains keys such as 'name', 'type', 'size', 'tmp_name', and 'error'. These keys represent different attributes of the uploaded file. 'name' represents the original name of the file, 'type' represents the MIME type, 'size' represents the file size in bytes, 'tmp_name' represents the temporary file name/location on the server, and 'error' represents any error status associated with the file upload.

Which of the following are differences between variables and constants in PHP?

  • Variables can be changed during the execution of the script, while constants cannot
  • Variables are case-sensitive, while constants are case-insensitive
  • Variables need to be explicitly declared using the $ sign, while constants do not need explicit declaration
  • All of the above
All of the above options are differences between variables and constants in PHP. Variables in PHP can have their values changed during the execution of the script, whereas constants are fixed and cannot be modified once defined. Variables are case-sensitive, meaning that different cases of the same variable name are treated as separate entities. On the other hand, constants are case-insensitive, allowing for consistent access regardless of the case used. Variables need to be explicitly declared using the $ sign, while constants do not require explicit declaration statements. Learn more: https://www.php.net/manual/en/language.variables.basics.php https://www.php.net/manual/en/language.constants.php

You have a PHP script and you need to access the session variables. How would you do this?

  • $_SESSION
  • $_REQUEST
  • $_SESSION_VARIABLES
  • $_GLOBAL
To access session variables in PHP, you can use the $_SESSION superglobal array. It allows you to store and retrieve data across multiple pages or requests within the same session. The values stored in $_SESSION are specific to each individual user session. For further information, visit: http://php.net/manual/en/reserved.variables.session.php

You need to prevent form submission in your PHP script if a required field is left empty. How would you do this?

  • Use JavaScript to validate the form before submitting it
  • Check if the field is empty using the empty() function and display an error message if it is
  • Implement client-side validation using HTML5 required attribute
  • Use CSS to visually indicate the required fields and prompt the user to fill them
To prevent form submission in PHP when a required field is left empty, you can check if the field is empty using the empty() function. If the field is empty, you can display an error message to the user. This ensures that the form is not submitted until all required fields are filled. For further information on form validation in PHP, refer to: php.net/manual/en/tutorial.forms.php#tutorial.forms.validation

In PHP, you can define a static method using the static keyword like public static function FunctionName() { ______ }.

  • // method implementation
  • return;
  • // your code here
  • // static method
In PHP, you can define a static method using the static keyword. The syntax for defining a static method is: public static function FunctionName() { // method implementation }. The static keyword is placed before the function name, indicating that it is a static method. You can then provide the implementation of the method inside the function body.

When is the elseif statement used in PHP?

  • When you need to evaluate multiple conditions sequentially and execute the first block of code that meets the condition
  • When you need to repeat a block of code multiple times
  • When you need to define a function with multiple arguments
  • When you need to concatenate multiple strings
The elseif statement in PHP is used when you need to evaluate multiple conditions sequentially and execute the first block of code that meets the condition. It allows you to provide an alternative set of conditions to be checked after the initial if condition is false. If any of the elseif conditions are met, the corresponding code block will be executed, and the remaining elseif and else conditions will be skipped. This enables you to create a chain of conditional checks and execute different code blocks based on different conditions. Learn more: https://www.php.net/manual/en/control-structures.elseif.php

Which of the following are true about the default keyword in a PHP switch statement?

  • It specifies the code to execute if no case matches the expression
  • It represents a specific case value
  • It is optional in every switch statement
  • It can only be used with strings
The default keyword in a PHP switch statement specifies the code to execute if no case matches the expression. It serves as the default option when none of the case conditions evaluate to true. The default case is optional and is placed at the end of the switch statement. If no case matches the expression, the code block following the default case is executed. The default case allows you to define a fallback action or a default behavior when none of the specific cases are met. Learn more: https://www.php.net/manual/en/control-structures.switch.php