GIF89a; %PDF-1.5 %���� ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµùÕ5sLOšuY
Server IP : 134.29.175.74 / Your IP : 216.73.216.160 Web Server : nginx/1.10.2 System : Windows NT CST-WEBSERVER 10.0 build 19045 (Windows 10) i586 User : Administrator ( 0) PHP Version : 7.1.0 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /nginx/html/JimMartinson/CST1146/Labs/Lab06/ |
Upload File : |
<? // JimMartinson/CST1146/Labs/Lab03/Lab03.phpinc #if ( $_SESSION['userId'] == 1 ) $showEvaluationVariables = true; require('Gradebook/EvaluationSubmission_BEGIN.phpinc'); // Replaced. #if ( $_SESSION['userId'] != 1 ) { require('Gradebook/EvaluationSubmission_END.phpinc'); exit; } include('common/Browser/Browser.phpinc'); $disabled = ''; $disabled = ' disabled'; // Comment this line to enable lab. // NOTE: Disable Include conf/extra/httpd-autoindex.conf line in the httpd.conf file before labs. // OR: Fix labs so Lab 4 mod_autoindex works as it should. ?> <fieldset><legend><?=$evaluationType?> <?=$evaluationNumber?> Description</legend> The purpose of this lab is to demonstrate the use of php arrays. <?=$gradeNote?> <? if ( $disabled ) { ?><span class="error bold">Notice: Do not perform this assignment unless this notice has been removed.</span><? } ?> </fieldset> <fieldset><legend><?=$evaluationType?> <?=$evaluationNumber?> Instruction</legend> <ol class="count"> <!-- 1 --> <li>Create a directory called <b class="copyText"><?=$evaluationName?></b> in your <b><?=$dataFolder?><?=$dirSep?><?=$courseNumber?></b> directory. We will use it for all work performed in this lab.</li> <!-- 2 --> <li>Create a PHP file called <b class="copyText"><?=$saveFilename?>.php</b> in the <b><?=$evaluationName?></b> directory and open it in an editor. <br>All code below will be written into this file. <br>Create a stub file with the <span class="php">$labNumber</span>, <span class="php">$myName</span>, <span class="html">!DOCTYPE</span>, <span class="html">html</span>, <span class="html">head</span>, <span class="html">title</span>, <span class="html">meta charset</span>, and <span class="html">body</span>, and <span class="html">h1</span> variables, elements, and tags. <span class="note"><a href="#notes">See notes</a>.</span> </li> <!-- 3 --> <li>Demonstrate the use of indexed arrays: <ol> <li>Add an <span class="html">h2</span> heading with the content: <span class="html copyText">Indexed array</span>.</li> <li>Create an array named <span class="php">$arrayOne</span> using the array() function with the values <span class="code copyText">1, 2, 9, 4</span>.</li> <li>Display the $arrayOne array.</li> <li>Add a new value to the $arrayOne array using the <span class="php copyText">$arrayOne[]</span> syntax with a value of <span class="code copyText">3</span>.</li> </ol> <span class="note">Add text to describe what is being displayed and on separate lines. Display all values using the php var_dump() function and html pre tag.</span> </li> <!-- 4 --> <li>Demonstrate the use of out of order indexed arrays: <ol> <li>Add an <span class="html">h2</span> heading with the content: <span class="html copyText">Indexed out of order</span>.</li> <li>Unset the second index of the <b>$arrayOne</b> array with <span class="php copyText">unset($arrayOne[2]);</span>.</li> <li>Set the second index of the <b>$arrayOne</b> array with <span class="php copyText">$arrayOne[2] = 8;</span>.</li> <li>Display the $arrayOne array.</li> <li>Create an array named <span class="php">$arrayTwo</span> using the array() function with the values <span class="code copyText">4 => "<?=$userFirstName?>", 2 => "<?=$userLastName?>", 6 => "<?=$userShortName?>", 0 => "<?=$classNumber?>"</span>.</li> <li>Display the $arrayTwo array.</li> </ol> <span class="note">Add text to describe what is being displayed and on separate lines. Display all values using the php var_dump() function and html pre tag.</span> </li> <!-- 5 --> <li>Demonstrate the use of associative arrays: <ol> <li>Add an <span class="html">h2</span> heading with the content: <span class="html copyText">Associative array</span>.</li> <li>Create an associative array named <span class="php">$assoc</span> using the array() function with the values <span class="code copyText">"first" => "<?=$userFirstName?>", "last" => "<?=$userLastName?>", "full" => "<?=$userFullName?>", "class" => "<?=$classNumber?>"</span>.</li> <li>Display the $assoc array.</li> </ol> <span class="note">Add text to describe what is being displayed and on separate lines. Display all values using the php var_dump() function and html pre tag.</span> </li> <!-- 6 --> <li>Demonstrate the use sort(): <ol> <li>Add an <span class="html">h2</span> heading with the content: <span class="html copyText">sort()</span>.</li> <li>Sort $arrayOne using sort().</li> <li>Display the $arrayOne array.</li> <li>Sort $arrayTwo using sort().</li> <li>Display the $arrayTwo array.</li> </ol> <span class="note">Add text to describe what is being displayed and on separate lines. Display all values using the php var_dump() function and html pre tag.</span> </li> <!-- 7 --> <li>Demonstrate the use asort(): <ol> <li>Add an <span class="html">h2</span> heading with the content: <span class="html copyText">asort()</span>.</li> <li>Add a new value to the $arrayTwo with <span class="php copyText">$arrayTwo[10] = "AAA";</span>. <ins>2021-10-26 Changed 'aaa' to 'AAA'.</ins></li> <li>Sort $arrayTwo using asort().</li> <li>Display the $arrayTwo array.</li> </ol> <span class="note">Add text to describe what is being displayed and on separate lines. Display all values using the php var_dump() function and html pre tag.</span> </li> <!-- 8 --> <li>Demonstrate the use ksort(): <ol> <li>Add an <span class="html">h2</span> heading with the content: <span class="html copyText">ksort()</span>.</li> <li>Sort $assoc using ksort().</li> <li>Display the $assoc array.</li> </ol> <span class="note">Add text to describe what is being displayed and on separate lines. Display all values using the php var_dump() function and html pre tag.</span> </li> <!-- 9 --> <li>Verify that your page works. <ol type="i"> <li>Start Apache if it is not running.</li> <li>Open up a browser.</li> <li>In the address bar enter <b class="copyText">http://localhost/CST1146/<?=$evaluationName?>/</b> and hit enter.</li> <li>Click on your <b><?=$saveFilename?>.php</b> file. <br>You should see a page like: <note>(Without the notes)</note><br> <? BrowserBegin('Lab '.$evaluationNumber.' - '.$userFullName,'http://localhost/CST1146/'.$saveFilename.'.php',820); ?> <h1 class="left">Lab <?=$evaluationNumber?> - <?=$userFullName?></h1> <h2>Indexed array</h2> <?php $arrayOne = array(1, 2, 9, 4); ?> <span class="note">The array $arrayOne has 4 values.</span><br> $arrayOne = <pre><?=var_dump($arrayOne)?></pre> <?php $arrayOne[] = 3; ?> <span class="note">The array $arrayOne now has five values.</span><br> $arrayOne = <pre><?=var_dump($arrayOne)?></pre> <h2>Indexed out of order</h2> <?php unset($arrayOne[2]); $arrayOne[2] = 8; ?> <span class="note">The array $arrayOne now shows index 2 as the last value in the array. When it was unset, $arrayOne[2] was destroyed. When we gave $arrayOne[2] the new value, $arrayOne[2] was appended to the end of the array.</span><br> $arrayOne = <pre><?=var_dump($arrayOne)?></pre> <?php $arrayTwo = array(4 => $userFirstName, 2 => $userLastName, 6 => $userShortName, 0 => $classNumber); ?> <span class="note">$arrayTwo shows the 4 values in the order they were created. The indexes are not in order.</span><br> $arrayTwo = <pre><?=var_dump($arrayTwo)?></pre> <h2>Associative array</h2> <?php $assoc = array("first" => $userFirstName, "last" => $userLastName, "full" => $userFullName, "class" => $classNumber); ?> <span class="note">The array $assoc has 4 values in the order they were created.</span><br> $assoc = <pre><?=var_dump($assoc)?></pre> <h2>sort()</h2> <?php sort($arrayOne); ?> <span class="note">$arrayOne now lists the values in order.</span><br> $arrayOne = <pre><?=var_dump($arrayOne)?></pre> <?php sort($arrayTwo); ?> <span class="note">$arrayTwo now lists the values in order. The $arrayTwo indexes are also renumbered 0,1,2,3 when they were 4,2,6,0 before.</span><br> $arrayTwo = <pre><?=var_dump($arrayTwo)?></pre> <span class="note">We did not see this with $arrayOne above because there were no missing index numbers. They were already 0,1,2,3,4. <br>The sort function always re-indexes the array.</span><br> <h2>asort()</h2> <?php $firstBefore = $arrayTwo[0]; $arrayTwo[10] = "AAA"; asort($arrayTwo); ?> <span class="note">$arrayTwo still lists the values in order, but the first item (which was "<?=$firstBefore?>") is now the second even though the index is still 0.</span><br> <ins><span class="note">I Fixed the demo output. I had zzz instead of AAA. 2021-10-26 Changed 'aaa' to 'AAA' and fixed note above.</span></ins><br> $arrayTwo = <pre><?=var_dump($arrayTwo)?></pre> <?php /** / asort($arrayTwo, SORT_STRING | SORT_FLAG_CASE); ?> $arrayTwo = <pre><?=var_dump($arrayTwo)?></pre> <?php /**/ ?> <h2>ksort()</h2> <?php ksort($assoc); ?> <span class="note">$assoc now lists the array sorted by the index instead of the order in which they were created.</span><br> $assoc = <pre><?=var_dump($assoc)?></pre> <? BrowserEnd(); ?> If this is not what you see then you have errors in your code. </li> <li><b class="info">Take a screenshot of the page</b> and save the image as <b class="copyText"><?=$saveFilename?>.png</b> in your <b><?=$dataFolder?><?=$dirSep?><?=$courseNumber?><?=$dirSep?><?=$evaluationName?></b> directory. <br>Make sure that the address bar is visible in your browser before saving the image. </li> </ol> </li> <!-- 10 --> <li>Turn in your assignment: <ol> <li>Ensure the following files are in your <b><?=$evaluationName?></b> folder. <br><?=$saveFilename?>.php <br><?=$saveFilename?>.png </li> <li>Zip up your <b><?=$evaluationName?></b> folder into a file named <b class="copyText"><?=$uploadFilename?></b>.</li> <li>Browse and select your <b><?=$uploadFilename?></b> file: <input type="file" name="fileUpload" id="inpFileUpload"<?=$disabled?>><div id="divFileploadError"></div></li> <li>Then <input type="submit" name="f_subtask" id="inpSubmit" value="Submit"<?=$disabled?>> for grading.</li> </ol> </li> </ol><? if ( $disabled ) { ?><span class="error bold">Notice: Do not perform this assignment unless this notice has been removed.</span><? } ?> </fieldset> <? require('../LabNotes.phpinc'); require('Gradebook/EvaluationSubmission_END.phpinc'); // Replaced. ?>