TAILIEUCHUNG - Object-Oriented Programming with PHP 5 phần 7

Trong ví dụ thú vị được thể hiện dưới đây, chúng tôi đang mở rộng ArrayObject và tạo ra một ExtendedArrayObject linh hoạt hơn đối với nguyên mẫu như chức năng. Các mảng mở rộng cung cấp vượt qua dễ dàng hơn thông qua bộ sưu tập. Chúng ta hãy có một cái nhìn: | Standard PHP Library In the interesting example shown below we are extending Arrayobject and creating a more flexible ExtendedArrayObject for prototype like functionality. The extended array provides easier traversing through the collection. Let s have a look class ExtendedArrayObject extends Arrayobject private _array public function constructs if is_array func_get_arg 0 this- _array func_get_arg 0 else this- _array func_get_args parent __construct this- _array public function each callback iterator this- getIterator while iterator- valid callback iterator- current iterator- next public function without args func_get_args return array_values array_diff this- _array args public function first return this- _array 0 public function indexOf value return array_search value this- _array public function inspect echo pre .print_r this- _array true . pre public function last 144 Chapter 6 return this- _array count this- _array -1 public function reverse applyToSelf false if applyToSelf return array_reverse this- _array else _array array_reverse this- _array this- _array _array parent __construct this- _array return this- _array public function shift _element array_shift this- _array parent __construct this- _array return _element public function pop _element array_pop this- _array parent __construct this- _array return _element If you want to see how to use it here it goes include_once function speak value echo value newArray new ExtendedArrayObject array 1 2 3 4 5 6 or you can use this newArray new ExtendedArrayObject 1 2 3 4 5 6 newArray- each speak pass callback for loop print_r newArray- without 2 3 4 subtract newArray- inspect display the array in a nice manner 145 Standard PHP Library echo newArray- indexOf 5 position by value print_r newArray- reverse reverse the array print_r newArray- reverse true for changing array itself echo newArray- shift shifts the first value of the array and returns it echo newArray- pop pops out the last .

TỪ KHÓA LIÊN QUAN
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.