A constant in a PHP class is defined using the const keyword.
- TRUE
- FALSE
- nan
- nan
A constant in a PHP class is indeed defined using the const keyword. It allows you to define a constant within a class by specifying the constant name, the assignment operator =, and the desired value. For example: const CONSTANT_NAME = value; Constants are used to store values that remain the same throughout the execution of a script and cannot be changed once defined. They provide a convenient way to define and use fixed values within a class. Refer to: http://php.net/manual/en/language.constants.php
You have a PHP script and you need to include a file, but you want to continue execution of the script even if the file is not found. Which statement would you use and why?
- include()
- require()
- include_once()
- require_once()
To include a file in your PHP script and continue execution even if the file is not found, you would use the include() statement. If the file is not found, a warning will be generated, but the script execution will continue without causing a fatal error.
In PHP, $_GET is a superglobal array that is used to collect data sent in the URL's ______.
- Query string
- Request body
- Path parameters
- Headers
In PHP, the $_GET superglobal is used to collect data sent in the URL's query string. When data is sent to the server through the URL using the GET method, the values are appended to the URL as key-value pairs in the query string. The $_GET superglobal allows access to these values by using the corresponding key as an index. It is commonly used to retrieve parameters or values passed through the URL. Learn more: https://www.php.net/manual/en/reserved.variables.get.php
A static method in PHP OOP is a method that belongs to the class itself rather than an instance of the class.
- TRUE
- FALSE
- nan
- nan
A static method in PHP OOP is a method that belongs to the class itself rather than an instance of the class. It can be accessed using the class name without creating an object of the class.
You need to store a price, which includes cents, in a variable in your PHP script. What type of number would you use and why?
- float
- integer
- string
- boolean
In this case, you would use the float data type to store a price that includes cents in a variable in your PHP script. The float data type allows for the representation of real numbers with a decimal point, which is suitable for storing prices that may have fractional values, such as cents. Integer data type is not suitable as it does not allow for decimal points. String data type could be used, but it is more appropriate to use float to perform arithmetic calculations if needed. Learn more: https://www.php.net/manual/en/language.types.float.php
You have installed PHP on your local machine, but your PHP script isn't running. What could be potential reasons for this?
- PHP isn't properly installed.
- The web server isn't properly configured to handle PHP files.
- The PHP file has a syntax error.
- All of the above.
There could be several reasons why a PHP script isn't running. PHP might not be properly installed, or the web server might not be correctly configured to handle PHP files. There could also be syntax errors within the PHP script that prevent it from executing correctly. In some cases, file permissions or the PHP configuration file (php.ini) settings can also cause issues. Learn more: https://www.php.net/manual/en/install.php
What are some FTP-related functions available in PHP?
- ftp_connect(), ftp_login(), ftp_put()
- array_merge(), json_encode(), htmlspecialchars()
- trim(), substr(), strtolower()
- All of the above
PHP provides several FTP-related functions for working with FTP servers. Some commonly used FTP functions in PHP include ftp_connect() (to establish an FTP connection), ftp_login() (to log in to an FTP server), and ftp_put() (to upload a file to an FTP server). Other functions like ftp_get() (to download a file), ftp_nlist() (to retrieve a directory listing), ftp_mkdir() (to create a directory), and ftp_delete() (to delete a file) are also available. These functions allow PHP scripts to interact with FTP servers and perform file transfer operations.
Which PHP loop will execute a block of code at least once, then it will repeat the loop as long as the condition is true?
- while loop
- for loop
- do-while loop
- foreach loop
The do-while loop in PHP will execute a block of code at least once, and then it will repeat the loop as long as the specified condition is true. In this loop, the condition is checked after the code block is executed, ensuring that the block of code is executed at least once. If the condition evaluates to true, the loop will continue to repeat. If the condition evaluates to false, the loop will terminate. The do-while loop is useful when you want to guarantee the execution of the code block at least once, regardless of the condition. Learn more: https://www.php.net/manual/en/control-structures.do.while.php
You need to replace a certain word in a string in your PHP script. How would you do this?
- str_replace($search, $replacement, $string)
- replace($search, $replacement, $string)
- substr_replace($search, $replacement, $string)
- swap($search, $replacement, $string)
To replace a certain word in a string in PHP, you can use the str_replace() function. The str_replace() function performs a search and replace operation on a given string. It replaces all occurrences of the specified search string with the replacement string. Pass the search string, replacement string, and the original string as arguments to the str_replace() function, like this: str_replace($search, $replacement, $string). This will return a new string with the replaced word. Learn more: https://www.php.net/manual/en/function.str-replace.php
In PHP, a function is a self-contained block of code that performs a specific task.
- TRUE
- FALSE
Yes, in PHP, a function is a self-contained block of code that performs a specific task. It is a way to organize and reuse code in a modular manner. Functions can take input parameters and return a value or perform an action. They help improve code readability and maintainability. Learn more: https://www.php.net/manual/en/functions.user-defined.php