TAILIEUCHUNG - PHP 5 Recipes A Problem-Solution Approach 2005 phần 3

CÁC TÍNH NĂNG NGÔN NGỮ - Mô hình hướng đối tượng mới Khi Zeev Suraski đưa cú pháp hướng đối tượng vào PHP từ cái thời của PHP3 thì những lập trình viên chuyên nghiệp có thể dễ dàng nhận ra chúng giống như một thứ gia vị để truy cập vào các collection. | 4-21 EXTRACTING A PORTION OF AN ARRAY 153 Beginning with PHP you can cause the array returned by this function to preserve the indexes of the original by passing an additional argument of TRUE slice2 array_slice languages 2 count languages - 2 TRUE printf pre Slice 2 n s pre n var_export slice2 TRUE How It Works You can see how this works by examining the output of the previous code and comparing slice1 and slice2 Original array array 0 French 1 German 2 Russian 3 Chinese 4 Hindi 5 Quechua 6 Spanish 7 Hausa Slice 1 array 0 Russian 1 Chinese 2 Hindi 3 Quechua 4 Spanish 5 Hausa Slice 2 array 2 Russian 3 Chinese 4 Hindi 5 Quechua 6 Spanish 7 Hausa 154 4-22 EXTRACTING VALUES FROM ARRAYS WITH EXTRACT You can also use negative values for Soffset and or length. If Soffset is negative then the slice returned will start abs Soffset elements from the end of the array if Slength is negative then the slice will end abs Slength elements from the end of the array. For instance given the following slice3 array_slice Slanguages -6 -2 TRUE then slice3 will be identical to slice2 from the previous example. Finally you can obtain a slice consisting of all elements of an array beginning with the element at index Soffset all the way through to the end of the array simply by omitting the length argument. Assuming that Slanguages is the same array as defined in the last two examples then the following last3 array_slice languages -3 printf p Last 3 s p n var_export last3 TRUE will produce this output Last 3 array 0 Quechua 1 Spanish 2 Hausa Note that if you want to preserve the original keys you must supply Slength as well as preserve_keys as using 0 or any value that converts to 0 such as an empty string or NULL for Slength will return an empty array. To get a slice consisting of the last three elements in Slanguages while preserving the keys you would need to use something like this Slast3 array_slice Slanguages -3 3 TRUE printf p Last 3 s p n var_export Slast3 TRUE This will .

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.