Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
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@soict.hut.edu.vn 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 1.1. What is an Array? Array? 1.2. 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 – (e.g., 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 – (e.g., 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 2.1. 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 2.2. 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[] = .