Which of the following are true about arrays in PHP?
- Arrays can only store values of the same data type.
- Arrays can have both numeric and string keys.
- Arrays cannot be nested within each other.
- Arrays cannot be modified once they are created.
In PHP, arrays can have both numeric and string keys. This allows for flexibility in accessing and organizing data within the array. Arrays can store values of different data types, including strings, integers, floats, booleans, and even other arrays. Additionally, arrays can be modified by adding, updating, or removing elements. Nesting arrays within each other is also possible, leading to multidimensional arrays. Learn more: https://www.php.net/manual/en/language.types.array.php
Which of the following are common uses of PHP?
- Creating static HTML pages.
- Advanced machine learning.
- Web scraping.
- High-performance game development.
While PHP can be used for a variety of tasks, one of its most common uses is web scraping, where PHP scripts can be written to automatically gather data from web pages. Learn more: https://www.php.net/manual/en/book.dom.php
What does $_COOKIE mean?
- An array of cookie variables
- A predefined cookie constant
- A function for handling cookies
- A global function
In PHP, $_COOKIE is an array that holds cookies sent by the client to the server. It provides access to cookie values. Learn more: http://php.net/manual/en/reserved.variables.cookies.php
What PHP superglobal array holds the information about uploaded files?
- $_FILES
- $_POST
- $_GET
- $_REQUEST
The $_FILES superglobal array in PHP holds the information about uploaded files. It provides access to the file name, temporary file location, file size, and other details of the uploaded file. This array is available after a file has been uploaded using an HTML form with the appropriate settings.
What is a common use case for the $_GET superglobal in PHP?
- Retrieving data sent via an HTML form using the GET method.
- Storing data in cookies.
- Accessing data from the URL's query string.
- Processing user input from an HTML form using the POST method.
A common use case for the $_GET superglobal in PHP is to access data from the URL's query string. This can include parameters or values passed through the URL, such as search queries, page identifiers, or filter criteria. By retrieving data from the query string using $_GET, you can dynamically generate content, perform searches, or filter data based on user input. However, it is not used for retrieving form data using the GET method or processing user input using the POST method. Learn more: https://www.php.net/manual/en/reserved.variables.get.php
What are some common practices in PHP when working with MySQL databases?
- Using prepared statements or parameterized queries
- Sanitizing and validating user input
- Handling database errors and exceptions
- All of the above
When working with MySQL databases in PHP, it is good practice to use prepared statements or parameterized queries to prevent SQL injection vulnerabilities. Sanitizing and validating user input is crucial to ensure the security and integrity of the data stored in the database. Additionally, handling database errors and exceptions appropriately helps in detecting and resolving issues during database operations. Following these practices helps in writing secure, reliable, and efficient PHP code when interacting with MySQL databases.
To access an element of a multidimensional array in PHP, you use the name of the array followed by the ______ of the element in square brackets.
- Index
- Key
- Value
- Position
To access an element of a multidimensional array in PHP, you use the name of the array followed by the index or key of the element in square brackets ([]). The index or key corresponds to the position or identifier of the element within the array hierarchy. By specifying the appropriate index or key for each dimension of the multidimensional array, you can access the desired element. This allows for targeted retrieval and manipulation of specific elements within the multidimensional array. Learn more: https://www.php.net/manual/en/language.types.array.php#language.types.array.syntax
You can use the include statement in PHP to include files from a remote server.
- TRUE
- FALSE
- nan
- nan
No, in PHP, the include statement is used to include local files present on the server where the PHP script is being executed. It cannot directly include files from a remote server. To include remote files, you would typically use other methods like file_get_contents() or cURL to fetch the remote file's content and then include it in your PHP script.
An abstract class in PHP OOP is a class that cannot be instantiated and is meant to be ______ by other classes.
- inherited
- implemented
- instantiated
- extended
An abstract class in PHP OOP is indeed a class that cannot be instantiated directly and is meant to be inherited by other classes. It serves as a blueprint or template for creating child classes that extend the abstract class. Abstract classes provide common functionality and structure that can be shared among multiple related classes. By inheriting from an abstract class, child classes can utilize the defined methods and properties and add their own specific implementations. To learn more, visit: http://php.net/manual/en/language.oop5.abstract.php
You are writing a PHP script and you need to create a MySQL table. How would you do this?
- Connect to the MySQL server, select the database, execute a CREATE TABLE query using mysqli_query
- Connect to the MySQL server, execute an INSERT INTO query using mysqli_query
- Connect to the MySQL server, execute a SELECT query using mysqli_query
- Connect to the MySQL server, execute a DELETE query using mysqli_query
To create a MySQL table in a PHP script, you would follow these steps: 1. Connect to the MySQL server using the appropriate credentials. 2. Select the database where you want to create the table. 3. Execute a CREATE TABLE query using the mysqli_query function. You would pass the connection object and the CREATE TABLE query as parameters to the mysqli_query function. This executes the query against the MySQL server. Make sure to handle any errors that may occur during the query execution.