Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

9. Suppose an associative array is added to a regular array by these statements:

ID: 3732769 • Letter: 9

Question

9. Suppose an associative array is added to a regular array by these statements: Scart- array) $item-array; Sitoml'itemCode'1 -123; Sitam 'itemName' visual Basic 2010 Sitom[ 'itemCost' -52.5 Sitem[ 'itemQuantity'-5 Scartt] $item To refer to the "itemCost" element in the associative array that's within the regular array, you would use this code: b. Scart'itemCost'110] d. $item [Scart('ite cost' 10. When you use session tracking, each HTTP request includes a. a URL that stores the session ID b. a cookie that stores the session ID c. a cookie that stores the session data d. a cookie that stores the session ID and the session data 11. If necessary, you can use PHP functions to do all but one of the following. Which one is it? a. get the name of the session cookie b. get the session ID c. generate a new session ID d. get the data for a session ID 12. The function that follows returns function coin toss) if (mt rand (o, 1)0) $coinheads else( $coin 'tails' return $coin; a random value between 0 and 1 a. b. a value of either 0 or 1 c. a value of either "heads" or "tails" d. a reference to the Scoin variable 13. To create a function named randomize that has one parameter that has a default value of 5 and one required parameter that's passed by reference, you start the function like this: a. function randomize ($Gparml, $parm2 5) b. funetion randomize (Sparml-S, $par) c. function randomize (&$parml, Spar 2 5) d. function randomize ($paral-5,parm2) {

Explanation / Answer

12-

function coin_toss()

{

if(mt_rand(0, 1) == 0)

$coin = 'tails';

else

$coin = 'heads';

return $coin;

}

(option c)returns either "heads" or "tails".

13-

first parameter has default value of 5 and second is passed by reference,

then we will start the function by

(option d) function randomize($parm1 = 5 , &$parm2)

9-  

$cart = array();
$item = array();

$item['itemcode'] = 123;
$item['itemName'] = "Visual Basic 2010";
$item['itemcost'] = 52.5;
$item['itemQuantity'] = 50;

$cart[] = $item;


echo $cart[0]['itemcost'];

will print out the cost of item.

so (option a)

11-

option d

we can get name of session by, session_name()

we can get session id by , session_id()

we can generate a new session id by, session_id($id); where $id contains the id of session.