From 6563b90471210a5819c9d68c975173d67eb29e72 Mon Sep 17 00:00:00 2001 From: Oni Emmanuel Date: Sun, 31 Jan 2021 00:27:32 +0100 Subject: [PATCH] My second week assignment on arrays --- oni_emmanuel/associative.php | 35 +++++++++++++++++++++++++++++++++++ oni_emmanuel/index.php | 27 +++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 oni_emmanuel/associative.php create mode 100644 oni_emmanuel/index.php diff --git a/oni_emmanuel/associative.php b/oni_emmanuel/associative.php new file mode 100644 index 0000000..50d7de1 --- /dev/null +++ b/oni_emmanuel/associative.php @@ -0,0 +1,35 @@ + [ + // "Favourite Players" => [ + "Mohammed Salah" =>[ + "Jersey No" => 11, + ], + "Roberto Firminho" =>[ + "Jersey No" => 9, + ], + "Sadio Mane" =>[ + "Jersey No" => 10, + ], + "Virgil Van Dirk" =>[ + "Jersey No" => 4, + ], + "Alexander Trent-Arnord" =>[ + "Jersey No" => 44, + ], + //], + //], + ]; + + //sorting Ascending + asort($players); + print_r($players); + echo "


"; + + + //sorting Descending + ksort($players); + print_r($players); + +?> \ No newline at end of file diff --git a/oni_emmanuel/index.php b/oni_emmanuel/index.php new file mode 100644 index 0000000..88a4351 --- /dev/null +++ b/oni_emmanuel/index.php @@ -0,0 +1,27 @@ +

"; + + //1. creating an array of multiples of 5 + $multipleOfFive = range(125, 800, 5); + + //2. printing of multiples of 5 + print_r($multipleOfFive); + echo $space; + + //3. printing numbers from their index values. + echo "The 17th item is " .$multipleOfFive[16]. ", and the 23rd item is " .$multipleOfFive[22]. ", and the 48th item is " .$multipleOfFive[47]; + echo $space; + + // 4. Echo the number of elements in the array. + echo count($multipleOfFive); + echo $space; + + //5. Sum of elements in the array + echo array_sum($multipleOfFive); + echo $space; + + //6. Shuffling and printing of the array + shuffle($multipleOfFive); + echo "The 17th item is " .$multipleOfFive[16]. ", and the 23rd item is " .$multipleOfFive[22]. ", and the 48th item is " .$multipleOfFive[47]; + echo $space; +?> \ No newline at end of file