PHP and MySQL Web Development - P26

PHP and MySQL Web Development - P26: PHP and MySQL Web Development teaches the reader to develop dynamic, secure, commercial Web sites. Using the same accessible, popular teaching style of the first edition, this best-selling book has been updated to reflect the rapidly changing landscape of MySQL and PHP. | 92 Chapter 3 Using Arrays A subtle point to note is the way we pass ampersand before the variable name in the definition of myMultiply means that value will be passed by reference. Passing by reference allows the function to alter the contents of the array. We will address passing by reference in more detail in Chapter 5. If you are not familiar with the term for now just note that to pass by reference we place an ampersand before the variable name. Counting Elements in an Array count sizeof and array_count_values We used the function count in an earlier example to count the number of elements in an array of orders. The function sizeof has exactly the same purpose. Both these functions return the number of elements in an array passed to will get a count of one for the number of elements in a normal scalar variable and 0 if you pass either an empty array or a variable that has not been set. The array_count_values function is more complex. If you call array_count_values array this function counts how many times each unique value occurs in the array array. This is the set cardinality of the array. The function returns an associative array containing a frequency table. This array contains all the unique values from array as keys. Each key has a numeric value that tells you how many times the corresponding key occurs in array. For example the following code array array 4 5 1 2 3 1 2 1 ac array_count_values array creates an array called ac that contains key value 4 1 5 1 1 3 2 2 3 1 This indicates that 4 5 and 3 occurred once in array 1 occurred three times and 2 occurred twice. Converting Arrays to Scalar Variables extract If we have an associative array with a number of key value pairs we can turn them into a set of scalar variables using the function extract . The prototype for extract is as follows extract array var_array int extract_type string prefix Other Array Manipulations 93 The purpose of extract is to take an array and create scalar .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
1    66    2    19-04-2024
61    265    2    19-04-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.