You need to access several global variables from within a function in your PHP script. How would you do this using the $GLOBALS superglobal?

  • Access each global variable directly using the $GLOBALS array and the variable name as the key. Use multiple statements to retrieve the values of different global variables.
  • Assign the $GLOBALS array to a local variable inside the function and use it to access the global variables. Assign each global variable to a separate local variable.
  • Use the 'extract' function to extract the values of all global variables into local variables inside the function.
  • Use the 'include' statement to include a file that contains the global variables and then access them within the function.
To access multiple global variables from within a function using the $GLOBALS superglobal, you can access each variable directly using the $GLOBALS array and the variable name as the key. You can use multiple statements to retrieve the values of different global variables. Each statement will access a specific global variable. Learn more: https://www.php.net/manual/en/reserved.variables.globals.php

You are writing a PHP script and you need to define an abstract class. How would you do this?

  • abstract class ClassName
  • final class ClassName
  • static class ClassName
  • var class ClassName
To define an abstract class in PHP, you can use the abstract keyword followed by the class keyword and the name of the class. For example: abstract class ClassName {} The abstract keyword indicates that the class is intended to be an abstract class. Abstract classes cannot be instantiated directly and are meant to be extended by other classes. They can contain abstract methods (without implementation) and non-abstract methods (with implementation). Refer to: http://php.net/manual/en/language.oop5.abstract.php

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

  • It represents a possible value for the expression
  • It is used to define the default case
  • It can only be followed by a numeric value
  • It is not required in every case block
The case keyword in a PHP switch statement represents a possible value for the expression. Each case block represents a specific value or condition that is evaluated against the switch expression. When a case value matches the expression, the corresponding block of code is executed. The case keyword allows you to define multiple possible values or conditions to be compared within the switch statement. Each case represents a potential match with the expression. Learn more: https://www.php.net/manual/en/control-structures.switch.php

Associative arrays in PHP use numeric keys.

  • TRUE
  • FALSE
False. In PHP, associative arrays use user-defined keys, which can be strings or numbers, instead of numeric keys. These keys are used to access the corresponding values in the array. Associative arrays provide a way to associate values with specific keys for easier retrieval and manipulation. The keys can be used to access the values in a non-sequential manner. Learn more: https://www.php.net/manual/en/language.types.array.php

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

  • To create an array by combining two arrays
  • To sort the elements of an array
  • To filter the elements of an array
  • To reverse the order of elements in an array
The array_combine() function in PHP is used to create an array by combining the values of one array as keys and another array as values. It takes two arrays as parameters and returns the combined array. This function is useful when you need to create an associative array from corresponding keys and values. Learn more: http://php.net/manual/en/function.array-combine.php

Which of the following are common uses of break and continue in PHP loops?

  • Terminating the loop when a specific condition is met.
  • Skipping specific iterations based on certain conditions.
  • Breaking out of nested loops.
  • Continuing to the next iteration of the loop.
  • All the options
The correct options are: "Terminating the loop when a specific condition is met," "Skipping specific iterations based on certain conditions," and "Breaking out of nested loops." These are common use cases for break and continue statements, allowing you to control the loop flow based on specific conditions or requirements. Learn more: https://www.php.net/manual/en/control-structures.break.php, https://www.php.net/manual/en/control-structures.continue.php

What is the difference between mysqli_fetch_object() and mysqli_fetch_array()?

  • The mysqli_fetch_object() function returns the current row of a result set as an object, while the mysqli_fetch_array() function returns the current row of a result set as an array.
  • The mysqli_fetch_object() function returns the current row of a result set as an array, while the mysqli_fetch_array() function returns the current row of a result set as an object.
  • The mysqli_fetch_object() function returns the current row of a result set as an associative array, while the mysqli_fetch_array() function returns the current row of a result set as both an associative array and a numeric array.
  • The mysqli_fetch_object() function returns the current row of a result set as a numeric array, while the mysqli_fetch_array() function returns the current row of a result set as both an associative array and a numeric array.
The mysqli_fetch_object() function and mysqli_fetch_array() function are used to fetch the current row of a result set in PHP, but they differ in the data structure they return. The mysqli_fetch_object() function returns the current row as an object, where each column is represented as an object property. On the other hand, the mysqli_fetch_array() function returns the current row as an array, where each column can be accessed by its numeric index or column name. Additionally, the mysqli_fetch_array() function supports both associative and numeric indexes, allowing you to retrieve column values using either approach. The choice between the two functions depends on your preferred data structure and how you want to access the fetched data.

How many types of arrays are there in PHP and what are they?

  • 1 type: numerical arrays.
  • 2 types: indexed arrays and associative arrays.
  • 3 types: linear arrays, multidimensional arrays, and linked lists.
  • 4 types: string arrays, integer arrays, boolean arrays, and object arrays.
In PHP, there are two types of arrays: indexed arrays and associative arrays. Indexed arrays are accessed using numeric indices, starting from 0, while associative arrays use keys that are strings or integers for accessing their elements. Indexed arrays are similar to traditional arrays in other programming languages, while associative arrays function like dictionaries or maps. Learn more: https://www.php.net/manual/en/language.types.array.php

If the condition in a PHP while loop is never false, the loop will ______.

  • continue indefinitely
  • terminate after one iteration
  • not be executed at all
  • execute the code block only once
If the condition in a PHP while loop is never false, the loop will continue indefinitely. The code block will be executed repeatedly as long as the condition remains true. It is important to ensure that the condition eventually becomes false to avoid infinite loops, as they can consume excessive resources and cause the program to become unresponsive. Infinite loops are generally unintended and can be caused by incorrect logic or a missing update in the loop control variable. It is essential to include logic within the loop to modify the condition or use control statements such as break or exit to terminate the loop when necessary. Learn more: https://www.php.net/manual/en/control-structures.while.php

In PHP, a multidimensional array can have as many dimensions as you need, although they can become hard to manage when they have more than ______ dimensions.

  • One
  • Two
  • Three
  • Four or more
In PHP, a multidimensional array can have as many dimensions as you need. While there is no specific limit on the number of dimensions, managing multidimensional arrays can become increasingly challenging as the number of dimensions increases. It is common to work with multidimensional arrays that have two or three dimensions, but when the number of dimensions goes beyond that, it can become harder to manage and reason about the data structure. In such cases, careful consideration should be given to the design and organization of the data to ensure maintainability and clarity in the code. Learn more: https://www.php.net/manual/en/language.types.array.php#language.types.array.syntax