The PHP function ________ is used to return all the keys of an array.

  • array_keys()
  • array_values()
  • array_diff()
  • array_map()
The array_keys() function is used to retrieve all the keys of an array, allowing you to work with array keys independently from their associated values.

You are building a function that processes user data. If the user does not provide an age, you want the function to default to 18. Which PHP feature allows you to set this default?

  • Default Parameters
  • Type Hinting
  • Variable Scope
  • Function Overloading
Default parameters in PHP allow you to set a default value for function parameters. If the user does not provide an age, the default value of 18 can be specified in the function signature.

Which of the following predefined PHP functions can be used to sort an array in descending order?

  • sort($array, SORT_DESC)
  • rsort($array)
  • asort($array, SORT_DESC)
  • arsort($array)
The correct option is 'rsort($array)'. This function is used to sort an array in descending order, where the keys stay associated with the corresponding values. 'sort($array, SORT_DESC)' and 'asort($array, SORT_DESC)' are incorrect, and 'arsort($array)' sorts in ascending order.

Which PHP function is used to split a string by a specified character or string?

  • explode()
  • substr()
  • split()
  • str_split()
The explode() function in PHP is used to split a string by a specified character or string. It returns an array of substrings. The other options are not used for this specific purpose.

What is the primary purpose of using transactions in database operations?

  • To ensure data security and integrity
  • To speed up database queries
  • To optimize data storage
  • To validate data
The primary purpose of using transactions in database operations is to ensure data security and integrity. Transactions allow you to group a series of database operations into a single, atomic unit. If any part of the transaction fails, all changes are rolled back, ensuring that the database remains in a consistent state. This is crucial in applications where data consistency is vital, such as banking or e-commerce systems.

How do you access the second element of an indexed array named $colors?

  • $colors[1]
  • $colors[0]
  • $colors.second()
  • $colors.element(2)
In PHP, arrays are zero-indexed, so the second element of an indexed array is accessed using "$colors[1]".

Which of the following is not a magic constant in PHP?

  • __FILE__
  • __DIR__
  • __FUNCTION__
  • __VARIABLE__
Magic constants in PHP are predefined constants, such as __FILE__, __DIR__, and __FUNCTION__, which provide information about the code's context. __VARIABLE__ is not a valid magic constant.

Which superglobal should be used in PHP to access session variables?

  • $_COOKIE
  • $_GET
  • $_SESSION
  • $_GLOBALS
In PHP, the $_SESSION superglobal is used to access and manipulate session variables. Session variables store user-specific data throughout a user's interaction with the web application.

In a scenario where you have a form with multiple checkboxes having the same name, how are the values sent to the PHP server?

  • Sent as an array
  • Sent as a string
  • Sent as individual keys
  • Sent as a JSON object
When multiple checkboxes share the same name, their values are sent to the PHP server as an array. This allows you to process multiple selections using PHP arrays.

How can you prevent a class from being inherited by another class in PHP?

  • Declare it as 'final'
  • Declare it as 'static'
  • Declare it as 'const'
  • Declare it as 'sealed'
To prevent a class from being inherited, you declare it as 'final.' The 'final' keyword indicates that the class cannot be extended by other classes.

It's considered good practice to keep your PHP code and HTML ________ to make the code more maintainable.

  • Separate
  • Combined
  • Nested
  • Parallel
It's good practice to keep your PHP code and HTML separate. This separation, often achieved with the Model-View-Controller (MVC) pattern, enhances code maintainability by segregating logic (PHP) from presentation (HTML).

If you want to include rows in a JOIN operation where there is no match in both tables, you would use a ________ JOIN.

  • INNER
  • OUTER
  • SELF
  • CROSS
To include rows where there's no match in both tables, you would use an "OUTER JOIN." This type of join includes unmatched rows from at least one of the tables.