Assignment Objectives & Purpose:
- Student's will learn how to create and use arrays.
- Student's will learn how to use functions with arrays.
- Student's will learn how to use loops to access arrays.
- The purpose of the assignment is to convert a string to an array.
- Student's will then manipulate the array as described below:
"John Jerry Ann Sanji Wen Paul Louise Peter"
(a.) Create an array out of the string by using the explode() function:
Array ( [0] => John [1] => Jerry [2] => Ann [3] => Sanji [4] => Wen [5] => Paul [6] => Louise [7] => Peter )
The number of elements in the array is: 8
(b.)Sort the Array (alphabetical sort):
Array ( [0] => Ann [1] => Jerry [2] => John [3] => Louise [4] => Paul [5] => Peter [6] => Sanji [7] => Wen )
(c.) Reverse the Array:
Array ( [0] => Wen [1] => Sanji [2] => Peter [3] => Paul [4] => Louise [5] => John [6] => Jerry [7] => Ann )
(d.) Remove the first element from the array:
Array ( [0] => Sanji [1] => Peter [2] => Paul [3] => Louise [4] => John [5] => Jerry [6] => Ann )
The number of elements in the array is now: 7
(e.) Add the elements "Willie" and "Daniel" to the end of the array:
Array ( [0] => Sanji [1] => Peter [2] => Paul [3] => Louise [4] => John [5] => Jerry [6] => Ann [7] => Willie [8] => Daniel )
The number of elements in the array is now: 9
(f.) Replace the element "Paul" with "Andre":
Array ( [0] => Sanji [1] => Peter [2] => Andre [3] => Louise [4] => John [5] => Jerry [6] => Ann [7] => Willie [8] => Daniel )
(g.) Add the element "Alisha" to the beginning of the array:
Array ( [0] => Alisha [1] => Sanji [2] => Peter [3] => Andre [4] => Louise [5] => John [6] => Jerry [7] => Ann [8] => Willie [9] => Daniel )
The number of elements in the array is now: 10
(h.) Create a new array of names:
Array ( [0] => Lauran [1] => Andrea [2] => Steven [3] => Diane )
(i.) Merge the two arrays and display in sorted oder:
Array ( [0] => Alisha [1] => Andre [2] => Andrea [3] => Ann [4] => Daniel [5] => Diane [6] => Jerry [7] => John [8] => Lauran [9] => Louise [10] => Peter [11] => Sanji [12] => Steven [13] => Willie )
The number of elements in the array is now: 14