Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Array Seree Chinodom Department of Computer Science.

Similar presentations


Presentation on theme: "1 Array Seree Chinodom Department of Computer Science."— Presentation transcript:

1 1 Array Seree Chinodom Department of Computer Science

2 2 Introduction n Student name 1 n Student name 2 n Student name 3 n Student name 4 n Student name 5 Student[1] Student[2] Student[3] Student[4] Student[5]

3 3 Student name :#student[4]#

4 4 n

5 5 Multiple Dimensions n One - Dimensional Array n Two - Dimensional Array

6 6 Createing Arrays n Arraynew function u one dimension { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/4361934/14/slides/slide_5.jpg", "name": "6 Createing Arrays n Arraynew function u one dimension

7 7 Populateing Array n One Dimension

8 8 Populateing Array n Two Dimension

9 9 Populateing Array n Three Dimension etc

10 10 Dynamic array NameofArray[1] NameofArray[2] NameofArray[3] NameofArray[1] NameofArray[2] NameofArray[4]

11 11 Dynamic array NameofArray[1] = “one” NameofArray[2] =“two” NameofArray[3] =“three” NameofArray[4] =“four” n delete NameofArray[3] =“three” NameofArray[1] = “one” NameofArray[2] =“two” NameofArray[3] =“four”

12 12 Array function n ArrayAppend n ArrayPrepend n ArrayDeleteAt n ArrayInsertAt n ArrayMax n ArrayMin n ArraySum n ArrayAvg n ArraySwap  ArraySort  ArrayClear  ArrayResize  ArrayIsEmpty  IsArray  ArrayNew  ArrayToList  ListToArray  ArraySet  ArrayLen

13 13 Common Array function n ArrayAppend Appends an array index to the end of the specified array. Returns a Boolean TRUE on successful completion. n Syntax ArrayAppend(array, value)

14 14 ArrayPrepend n Adds an array element to the beginning of the specified array. Returns a Boolean TRUE on successful completion. n Syntax ArrayPrepend(array, value)

15 15 ArrayDeleteAt n Deletes data from the specified array at the specified index position. Note that when an array index is deleted, index positions in the array are recalculated. For example, in an array containing the months of the year, deleting index position [5] removes the entry for May. If you then want to delete the entry for November, you delete index position [10], not [11], since the index positions were recalculated after index position [5] was removed.

16 16 ArrayDeleteAt n Syntax ArrayDeleteAt(array, position)

17 17 ArrayInsertAt n Inserts data in the specified array at the specified index position. All array elements with indexes greater than the new position are shifted right by one. The length of the array increases by one index. n Returns a Boolean TRUE on successful completion. n Syntax ArrayInsertAt(array, position, value)

18 18 Function for Processing Values Stored in an Array n ArrayMax: Returns the largest numeric value in the specified array n ArrayMin: Returns the smallest numeric value in the specified array n ArraySum : Returns the sum of values in the specified array. n ArrayAvg : Returns the average of the values in the specified array.

19 19 Example n ArrayName[1] = 1 n ArrayName[2] = 3 n ArrayName[3] = 2 n ArrayMax(ArrayName) -> 3 n ArrayMin(ArrayName) -> 1 n ArraySum(ArrayName) -> 6 n ArrayAvg(ArrayName) -> 2

20 20 Functions for Adjusting the Position of Elements in an Array ArraySwap n Swaps array values for the specified array at the specified positions. ArraySwap can be used with greater efficiency than multiple CFSETs. n Returns a Boolean TRUE on successful completion. n Syntax ArraySwap(array, position1, position2)

21 21 ArraySort n Returns the specified array with elements numerically or alphanumerically sorted. n Syntax ArraySort(array, sort_type [, sort_order ]) n sort_type : The type of sort to execute. Sort type can be: u numeric -- Sorts numerically u text -- Sorts text alphabetically, uppercase before lowercase u textnocase -- Sorts text alphabetically; case is ignored

22 22 Other Array functions n ArrayClear : Deletes all data in the specified array. Returns a Boolean TRUE on successful completion. n ArrayResize : Resets an array to a specified minimum number of elements. n ArrayIsEmpty : Determines whether the specified array is empty of data. n IsArray : Returns TRUE if value is an array. n ListToArray : Converts the specified list into an array. n ArrayToList : Converts the specified one dimensional array to a list, delimited with the character you specify.

23 23 Structure Function StructNew n Returns a new structure. n Syntax StructNew()

24 24 StructInsert n Inserts the specified key-value pair into the specified structure. Returns Yes if the insert was successful and n No if an error occurs. n Syntax StructInsert(structure, key, value [, allowoverwrite ])

25 25 StructUpdate n Updates the specified key with the specified value. Returns Yes if the function is successful and throws an exception if an error occurs. n Syntax StructUpdate(structure, key, value)

26 26 StructDelete n Removes the specified item from the specified structure. n Syntax StructDelete(structure, key [, indicatenotexisting ])

27 27 StructClear n Removes all data from the specified structure. Always returns Yes. n Syntax StructClear(structure)

28 28 StructCopy n Returns a new structure with all the keys and values of the specified structure. n Syntax StructCopy(structure)

29 29 StructCount n Returns the number of keys in the specified structure. n Syntax StructCount(structure)

30 30 StructFind n Returns the value associated with the specified key in the specified structure. n Syntax StructFind(structure, key)

31 31 StructKeyExists n Returns TRUE if the specified key is in the specified structure and FALSE if it is not. n Syntax StructKeyExists(structure, key)

32 32 StructIsEmpty n indicates whether the specified structure contains data. Returns TRUE if structure is empty and FALSE if it contains data. n Syntax StructIsEmpty(structure)

33 33 StructKeyArray n Returns an array of the keys in the specified ColdFusion structure. n Syntax StructKeyArray(structure)

34 34 StructKeyList n Returns the list of keys that are in the specified ColdFusion structure. n Syntax StructKeyList(structure, [delimiter])

35 35 IsStruct n Returns TRUE if variable is a structure. n Syntax IsStruct(variable )

36 36 Putting it all together n Create and populate a structure n Display the number of element in the structure n display the contents of the structure while deleting each element n display the number of element in the structure to verify that it is empty

37 37 Ssn.cfm There are #StructCount(SSN)# Social Security Number entries.

38 38 #socsec#: #StructFind(SSN,socsec)# There are #StructCount(SSN)# Social Security Number entries.

39 39 Ssn2.cfm There are #StructCount(SSN)# Social Security Number entries.

40 40 #socsec#: #SSN[socsec]# There are #StructCount(SSN)# Social Security Number entries.


Download ppt "1 Array Seree Chinodom Department of Computer Science."

Similar presentations


Ads by Google