1. Trang chủ
  2. » Mẫu Slide

Slide môn học PHP session 5 working with arrays

28 178 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 28
Dung lượng 146 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Define an array An array is a variable that can store a set of values of the same data type  Each value in an array is termed as an element  Each element of an array can be referred

Trang 1

Working with Arrays

Session 13

Trang 2

 Function is block of code that has

performs a specified job

 Functions enhance the logical flow

Trang 3

 Define an array

 Create and use array

 Merge array

 Use single and multidimensional arrays

 Use array-related functions

Trang 4

Define an array

 An array is a variable that can store

a set of values of the same data type

 Each value in an array is termed as an element

 Each element of an array can be referred by an array name and an index

 An array index is used to access an element

 An index can be a number or a string

Trang 6

array() Function - I

values of array elements

comma to create an array

associative arrays

Trang 7

array() Function - II

Syntax for creating an array using the

array() function is:

$array_name =

array([key => ] value,

[key => ] value)

Trang 8

Array Identifier

element in an array

the array identifier is:

$array_name[key] = “element_value”;

Trang 9

Indexed Array

integer

array, if the index type is not

specified at the time of creating

an array

integer, such as 1, 20, or 123

Trang 10

Indexed Array - Example

Trang 11

Associative Array

 An array where the index type is string

 Index value must be specified within

double quotes

Trang 12

Associative Array - Example

Trang 13

Merging Arrays

two or more arrays

$merged_array_name =

array_merge($first_array, $second_array);

Trang 14

Merged Array - Example

Trang 15

Multidimensional Arrays

 Each element is an array

 Each element requires an array name and

multiple set of indices

 Syntax for creating a multidimensional

array is:

$array_name = array(

array(key => value), array(key => value))

Trang 16

Multidimensional Array - Example

Trang 17

Array-related Functions - I

sort() - Arranges the element values into

an alphabetical order

rsort() - Sorts the element values in the

descending alphabetical order

arsort() - Sorts both associative and

Trang 18

Array-related Functions - II

array_flip() - Converts the element

values to index values and index values

to element values

array_intersect() - Identifies and

returns the common element value among

a group of arrays

array_keys() - Displays all the key

indices of the specified array

array_reverse() - Reverses the order of

the array elements

Trang 20

rsort() Function

descending alphabetical order

Trang 22

array_flip() Function

 Converts the element values to index

values and index values to element values

Trang 26

Summary - I

 A variable can store only one value at a time

 An array is a variable that can store a set

of values of the same data type

 Each value in an array is termed as an

element

 All the elements are referenced by a common

name

 An array index is used to access an element

 An index can be a number or a string

 If the index is a string, the array is an

Trang 27

Summary - II

 We can combine the element values of two or

more arrays This process is called as merging

arrays

 In a single-dimensional array, the element

includes only one level of key value pairs

 In the multidimensional array, each element is

an array Each element requires an array name

and multiple set of indices

 There are two types of arrays

Trang 28

Summary - III

index type is string

must be specified within double quotes

store another array within it

 sort()

 arsort()

 rsort()

 array_pop()

Ngày đăng: 30/11/2016, 22:11

TỪ KHÓA LIÊN QUAN