Which function in PHP returns a formatted string?
- sprintf()
- printf()
- str_format()
- format_string()
The sprintf() function in PHP is used to return a formatted string. It allows you to create formatted strings using placeholders and values, similar to printf() in C.
In dynamic forms where fields can be added or removed by the user, the server-side processing in PHP should use the ________ function to ensure data integrity.
- 'isset()'
- 'array_push()'
- 'count()'
- 'filter_var()'
The correct option is 'count().' In dynamic forms, where the number of fields can change, using 'count()' helps ensure data integrity by determining how many fields have been submitted and handling them appropriately. This is important for server-side validation.
How do you call a user-defined function in PHP?
- call myFunction()
- myFunction()
- invokeFunction(myFunction)
- execute myFunction()
To call a user-defined function in PHP, you simply use the function name followed by parentheses. For example, 'myFunction()' would call the function 'myFunction'.
How can you restrict the maximum file size for uploads in PHP through a form?
- Using .htaccess file
- Setting upload_max_filesize in php.ini
- Using $_FILES['size']
- Validating file size in PHP code
You can restrict the maximum file size for uploads in PHP through a form by setting the upload_max_filesize directive in the php.ini configuration file. This directive limits the size of uploaded files.
Which of the following data types in PHP is not scalar?
- int
- string
- array
- boolean
The non-scalar data type in PHP is an array. Arrays can hold multiple values and are not considered scalar because they are collections of values, not single values. Scalars include integers, strings, and booleans.
Which PHP superglobal array is used to collect form data sent via the GET method?
- $_GET
- $_POST
- $_REQUEST
- $_FORM
The $_GET superglobal array is used to collect form data sent via the GET method in PHP. It retrieves data from the URL's query string.
The function used to sort an indexed array in descending order is ________.
- rsort
- sort
- ksort
- asort
The function rsort is used to sort an indexed array in descending order, preserving the key-value associations.
The PHP superglobal used to collect form data sent via the POST method is ________.
- $_GET
- $_REQUEST
- $_POST
- $_SERVER
The PHP superglobal $_POST is used to collect form data sent via the POST method, allowing you to access form input data securely.
In PHP, which superglobal can be used to retrieve form data sent with the POST method?
- $_POST
- $_GET
- $_REQUEST
- $_FORM
To retrieve form data sent using the POST method in PHP, you should use the $_POST superglobal. It contains the form data as an associative array, making it easy to access and process user input.
To pass an argument by reference in a PHP function, you prepend the argument with the ________ symbol.
- &
- $
- @
- *
To pass an argument by reference in PHP, you prepend it with the '&' symbol. This allows the function to modify the original variable passed as an argument.