TAILIEUCHUNG - Học php, mysql và javascript - p 15

Mảng đa chiều Một tính năng thiết kế đơn giản trong cú pháp của PHP mảng làm cho nó có thể tạo ra các mảng của hơn một chiều. Trong thực tế, chúng có thể được như nhiều kích thước như bạn muốn (mặc dù nó là một ứng dụng hiếm hoi mà đi xa hơn ba). Và tính năng đó là khả năng bao gồm toàn bộ một mảng như là một phần của một số khác, và để có thể tiếp tục làm như vậy, giống như những vần điệu cũ: "Big bọ chét có ít bọ chét trên. | Multidimensional Arrays A simple design feature in PHP s array syntax makes it possible to create arrays of more than one dimension. In fact they can be as many dimensions as you like although it s a rare application that goes further than three . And that feature is the ability to include an entire array as a part of another one and to be able to keep on doing so just like the old rhyme Big fleas have little fleas upon their backs to bite em. Little fleas have lesser fleas add flea ad infinitum. Let s look at how this works by taking the associative array in the previous example and extending it see Example 6-10. Example 6-10. Creating a multidimensional associative array php products array paper array copier Copier Multipurpose inkjet Inkjet Printer laser Laser Printer photo Photographic Paper pens array ball Ball Point hilite Highlighters marker Markers misc array tape Sticky Tape glue Adhesives clips Paperclips echo pre foreach products as section items foreach items as key value echo section t key t value br echo pre To make things clearer now that the code is starting to grow I ve renamed some of the elements. For example seeing as the previous array paper is now just a subsection of a larger array the main array is now called products. Within this array there are three items paper pens and misc and each of these contains another array with key value pairs. If necessary these subarrays could have contained even further arrays. For example under ball there might be many different types and colors of ballpoint pens available in the online store. But for now I ve restricted the code to just a depth of two. Multidimensional Arrays 121 Once the array data has been assigned I use a pair of nested loops to print out the various values. The outer loop extracts the main sections from the top level of the array and the inner loop extracts the key value pairs for the categories within each section. As long as you remember that each level of the array works .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.