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

Create a php solution that displays the four buttons: ‘Add Name’ ‘Print all asce

ID: 3680514 • Letter: C

Question

Create a php solution that displays the four buttons:

‘Add Name’

‘Print all ascending’

‘Print all descending’

‘Clear all Names’

If “add name” button is clicked, the name must be added to an array.

If the “print all ascending” button is clicked, all the names in the list must be printed in ascending order.

If the “print all descending” button is clicked, all the names in the list must be printed in descending order.

If the “clear all names” button is clicked, all of the array must be cleared.

            Note: ALL generated pages must show all the buttons.

After I add name for second time, it should not replace the last item. It should add it to the end of the array. For example:

Begin:

array has 3 elements

"ADD NAME"

array has 4 elements

"ADD NAME"

array has 5 elements

Explanation / Answer

<html>
<body>
<form action="functioncalling.php">
<input type="text" name="txt" />
<input type="submit" name="add" value="Add" />
<input type="submit" name="print_asc" value="Print (Asc)" />
<input type="submit" name="print_dec" value="Print (Dec)" />
<input type="submit" name="clear" value="Clear" />
</form>

<?php
if($_GET){
if(isset($_GET['add'])){
add();
}elseif(isset($_GET['print_asc'])){
print_asc();
}elseif(isset($_GET['print_dec'])){
print_dec();
}elseif(isset($_GET['clear'])){
clear();
}
}
$a=array();
function add()
{
array_push($a,$name);
}
function print_asc()
{
sort($a);
$clength=count($a);
for($x=0;$x<$clength;$x++)
{
echo $a[$x];
echo "<br>";
}
}
function print_dec()
{
rsort($a);
$clength=count($a);
for($x=0;$x<$clength;$x++)
{
echo $a[$x];
echo "<br>";
}
function print_clear()
{
unset($GLOBALS['a']); }

?>.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote