$color1 = array('white', 'green', 'red', 'blue', 'black'); echo displayString($color1); echo "<br/>2---------------------------------------------<br/>"; //test of 2 $color2 = array('white', 'green', 'red'); echo displayUnorderedList($color2); echo "<br/>3---------------------------------------------<br/>"; //test of 3 $ceu = array("Italy" => "Rome", "Luxembourg" => "Luxembourg", "Belgium" => "Brussels", "Denmark" => "Copenhagen", "Finland" => "Helsinki", "France" => "Paris", "Slovakia" => "Bratislava", "Slovenia" => "Ljubljana", "Germany" => "Berlin", "Greece" => "Athens", "Ireland" => "Dublin", "Netherlands" => "Amsterdam", "Portugal" => "Lisbon", "Spain" => "Madrid", "Sweden" => "Stockholm", "United Kingdom" => "London", "Cyprus" => "Nicosia", "Lithuania" => "Vilnius", "Czech Republic" => "Prague", "Estonia" => "Tallin", "Hungary" => "Budapest", "Latvia" => "Riga", "Malta" => "Valetta", "Austria" => "Vienna", "Poland" => "Warsaw"); displayCapitalList($ceu); echo "<br/>4---------------------------------------------<br/>"; //test of 4 $x = array(1, 2, 3, 4, 5); print_r(deleteElementByKey($x, 0)); echo '<br/>'; print_r(deleteElementByKey($x, 3)); echo "<br/>5---------------------------------------------<br/>"; //test of 5 $color = array(4 => 'white', 6 => 'green', 11 => 'red'); echo getFirstElement($color); echo "<br/>7---------------------------------------------<br/>"; //test of 7 $x = array(1, 2, 3, 4, 5); print_r(insert("\$", $x, 2)); echo "<br/>8---------------------------------------------<br/>"; //test of 8 $f = array("Sophia" => "31", "Jacob" => "41", "William" => "39", "Ramesh" => "40"); printArray(sortValueAscending($f)); echo "<br/>"; printArray(sortValueDescending($f)); echo "<br/>";
function sortKeyDescending($array) { echo "<br/>sortKeyDescending<br/>"; $newArray = array(); do { $c = 0; foreach ($array as $key => $value) { if ($c == 0) { $maxKey = $key; $c = 1; continue; } elseif ($maxKey < $key) { $maxKey = $key; } } $newArray[$maxKey] = $array[$maxKey]; $array = deleteElementByKey($array, $maxKey); } while (count($array) != 0); return $newArray; }