In PHP, a callback function is a function that is passed as an argument to ______.

  • Another function
  • A class method
  • An event handler function
  • All of the above
In PHP, a callback function is a function that is passed as an argument to another function. It allows the receiving function to call the callback function at a later point in the code. Callback functions are commonly used in PHP for various purposes, such as event handling, dynamic function invocation, and more. The correct option is "Another function" as it covers the general use case of callback functions in PHP. For further information, consult the PHP documentation on callback functions: http://php.net/manual/en/language.types.callable.php

Which PHP function checks if a variable is a number or a numeric string?

  • is_numeric()
  • is_integer()
  • is_float()
  • is_string()
The is_numeric() function in PHP is used to check if a variable is a number or a numeric string. It returns true if the variable can be evaluated as a number, whether it is an integer or a float, or a numeric string. This function is useful when you need to validate the numeric nature of a variable. Learn more: https://www.php.net/manual/en/function.is-numeric.php

You need to extract a part of a string in your PHP script. How would you do this using Regular Expressions in PHP?

  • Use the preg_match() function with capturing groups in the Regular Expression pattern.
  • Use the strtolower() function to convert the string to lowercase.
  • Use the substr() function to extract the desired part of the string.
  • Use the is_string() function to check if the value is a string.
To extract a part of a string using Regular Expressions in PHP, you can use the preg_match() function with capturing groups in the Regular Expression pattern. By defining capturing groups within the Regular Expression pattern, you can specify the part of the string you want to extract. When a match is found, the preg_match() function will populate an array with the captured groups. You can then access the desired part of the string using the appropriate index in the array. This allows you to extract specific portions of a string based on a pattern defined by a Regular Expression. Learn more: https://www.php.net/manual/en/function.preg-match.php

The $_GET superglobal in PHP is an associative array.

  • TRUE
  • FALSE
The statement is true. In PHP, the $_GET superglobal is indeed an associative array. It contains key-value pairs where the keys represent the parameters or names of the variables passed through the URL's query string, and the corresponding values are the data associated with those keys. You can access this data using the $_GET['parameter'] syntax, where 'parameter' is the name of the key. Learn more: https://www.php.net/manual/en/reserved.variables.get.php

You are writing a PHP script and you need to set a cookie. How would you do this?

  • setcookie()
  • create_cookie()
  • set_cookie()
  • bake_cookie()
To set a cookie in PHP, you can use the setcookie() function. This function allows you to define the cookie name, value, expiration time, path, domain, and other parameters. By calling setcookie(), you can set the desired cookie in your PHP script. Refer to: http://php.net/manual/en/function.setcookie.php

You are writing a PHP script and you want to execute a block of code a certain number of times. Which type of loop would you use and why?

  • for loop
  • while loop
  • do-while loop
  • foreach loop
If you want to execute a block of code a certain number of times, you would use a for loop in PHP. The for loop allows you to specify the initialization, condition, and iteration in a single line, making it suitable for looping a specific number of times. You can set the initial value, define the condition to continue the loop, and specify how the value should be incremented or decremented after each iteration. The for loop provides a clear structure and precise control over the number of iterations, making it the appropriate choice when you need to repeat a block of code for a known number of times. Learn more: https://www.php.net/manual/en/control-structures.for.php

The ______ function in PHP is used to return the length of a string.

  • strlen()
  • count()
  • size()
  • length()
The strlen() function in PHP is used to return the length of a string. It counts and returns the number of characters in a string. It is a built-in PHP function specifically designed for finding the length of a string. Learn more: https://www.php.net/manual/en/function.strlen.php

How can you destroy a session in PHP?

  • session_destroy()
  • destroy_session()
  • end_session()
  • close_session()
To destroy a session in PHP, you can use the session_destroy() function. This function removes all session data and ends the current session. Additionally, you may need to call session_unset() to unset all session variables before calling session_destroy(). This combination ensures the complete destruction of the session. To learn more, check: http://php.net/manual/en/function.session-destroy.php

If you want to write to a file in PHP, you can use the fwrite() function where the first argument is the file pointer and the second argument is the ______.

  • file content
  • file path
  • file handle
  • file size
In PHP, the fwrite() function is used to write content to a file. The first argument is the file pointer obtained from fopen(), and the second argument is the content that you want to write to the file. It can be a string, an array converted to a string, or any other writable data.

In PHP, the ______ function is used to open a file.

  • open()
  • fopen()
  • read()
  • include()
In PHP, the fopen() function is used to open a file. It takes the path to the file and the mode as parameters. This function returns a file handle or pointer that can be used for file operations, such as reading or writing data.