tailieunhanh - ICT 5 Web Development - Chapter 4: Working with Arrays

ICT 5 Web Development - Chapter 4: Working with Arrays Benefits of arrays, Sequential arrays, sequential arrays, Multidimensional lists, What is an Array? Creating Associative Arrays, Using foreach with associative arrays. | Vietnam and Japan Joint ICT HRD Program Objectives To understand the benefits of using arrays in PHP To learn how to create and use sequential arrays and their functions To learn how to create and use nonsequential arrays and their functions ITC 5 – Web Programming Chapter 4. Working with Arrays Nguyen Thi Thu Trang trangntt@ 2 Content Content 1. Benefits of arrays 2. Sequential arrays 3. Non-sequential arrays Non4. Multidimensional lists 1. Benefits of arrays 2. Sequential arrays 3. Non-sequential arrays Non4. Multidimensional lists 3 4 1 . What is an Array? Array? . Why Use Arrays? An array is a special type of variable. – can hold multiple data values A sequential array keeps track of these data items by using sequential numbers – (., item 0, item 1, item 2, and so on) on) A nonsequential array or associative array keeps track of these data items by using character strings – (., item meat, item poultry, item dairy, and so on) on) Include a flexible number of list items. Examine each item more concisely. Using Loops to Repeat Statements Use special array operators and functions. 5 Content 6 . Creating Sequential Arrays 1. Benefits of arrays 2. Sequential arrays 3. Non-sequential arrays Non4. Multidimensional lists Use the array() function to create an array You could also create an array with y numerical data – $grades = array(66, 75, 85, 80); 7 8 2 Another way to create an array . Referencing Sequential Array Items You can also create an array by making i di id l value assignments ki individual l i t into the array variable name. To reference individual array items, use an array name and index pair For example, $students[] = 'Johnson'; Johnson' Indices are referenced sequentially: $students[] = 'Jones'; Jones' – $ $names = array('Denise', 'Ch i t h ' 'M tth ' ('D i ' 'Christopher', 'Matthew', 'Bryant'); 'Bryant'); – print ("$names[0], $names[1], $names[2], $names[3]"); $students[] = .

TỪ KHÓA LIÊN QUAN