ch 10/11
Suppose an associative array is added to a regular array by these statements: $cart = []; $item = []; $item['itemCode'] = 123; $item['itemName'] = "Java Programming"; $item['itemCost'] = 59.5; $item['itemQuantity'] = 5; $cart[] = $item; To refer to the "itemCost" element in the associative array that's within the regular array, you would use this code:
$cart[0]['itemCost']
To create a DateTime object that represents a due date that's 90 days after the current date, you use the following code:
$days = new DateInterval('P90D'); $due_date = new DateTime(); $due_date = $due_date->add($days);
If $today contains a DateTime object for December 25, 2021, what output would be produced by the code below? echo $today->format('n/j/y');
12/25/21
What will the value of the $numbers array be after the following code is executed? $numbers1 = [3, 4, 5]; $numbers2 = [8, 9];$numbers = [...$numbers1, ...$numbers2];
3, 4, 5, 8, 9
If $today contains a DateTime object for December 25, 2021, what output would be produced by the code below? echo $today->format('F d, Y');
December 25, 2021
Which PHP function returns the number of elements in an array?
count()
Which of the following is a method of a DateTime object that can be used to determine an amount of time between two dates or times?
diff()
To create a DateTime object for the current date, you use the ________________ keyword and pass no arguments to the constructor.
new
Which of the following is a PHP function that shuffles the values in an array in a random order?
shuffle()
To refer to an element in a rectangular array, you need to use ________________ indexes.
two
To create a DateTime object based on the date and time you specifiy, you use a/an ________________ template.
absolute
Which of the following functions would you use to define a constant that stores an array in PHP 7.0 or later?
define()
Which of the following is a method of a DateTime object that can be used to add a period of time to the date?
add()
Which one of the following can the spread operator NOT be used for?.
all of these
Which of the following functions can you use to modify a DateTime object?
all of these (modify(),setTime(),setDate())
Which of the following is a PHP function that is used to count the number of times each value in an array is used?
array_count_values()
Given the code that follows, which of these statements assigns "John Smith is 29" to $message? $employees = []; $employees['name'] = "John Smith"; $employees['age'] = 29;
$message = $employees["name"] . " is " . $employees["age"];
Code example 10-1 $current_date = new DateTime(); $due_days_diff = $current_date->diff($due_date); if ($current_date > $due_date) { $overdue_message = $due_days_diff->format( '%y years, %m months, and %d days overdue.'); } (Refer to code example 10-1) If $due_date contains a DateTime object for a date that comes 1 month and 7 days before the date stored in the $current_date variable, what will $overdue_message contain when this code finishes executing:
0 years, 1 months, and 7 days overdue.
When you use a for loop to process the values in a regular array, the counter value can be used as the ________________ for each element in the array.
index
Timestamps will encounter a/an _______ problem if they are not converted to DateTime objects.
Y2K38
