PHP design mode interator (iterator Mode)

Source: Internet
Author: User

Introduction: This is a detailed page of the PHP design mode interator (iterator mode). It introduces PHP, related knowledge, skills, experience, and some PHP source code.

Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 339659 'rolling = 'no'>

1 <? PHP
2 /**
3 * iterator Mode
4 *
5 * provides a method to access each element of an aggregation object sequentially without exposing the internal representation of the object.
6 */
7 interface interator
8 {
9 Public Function next ();
10 public function first ();
11 Public Function current ();
12 public function isdone ();
13}
14
15 class someinterator implements interator
16 {
17 private $ _ arr = array ();
18
19 public function _ construct ($ ARR)
20 {
21 $ this-> _ arr = $ arr;
22}
23
24 public function first ()
25 {
26 return $ this-> _ arr [0];
27}
28
29 public function current ()
30 {
31 Return Current ($ this-> _ ARR );
32}
33
34 public function next ()
35 {
36 return next ($ this-> _ ARR );
37}
38
39 public function isdone ()
40 {
41}
42}
43
44 $ objsomeinterator = new someinterator (Array (1, 2, 3, 4, 6, 7 ));
45 echo $ objsomeinterator-> first (), "<br/> ";
46 echo $ objsomeinterator-> next (), "<br/> ";
47 echo $ objsomeinterator-> current (), "<br/> ";
48 echo $ objsomeinterator-> current (), "<br/> ";
49 echo $ objsomeinterator-> next (), "<br/> ";
50 echo $ objsomeinterator-> current (), "<br/> ";

Love J2EE follow Java Michael Jackson video station JSON online tools

Http://biancheng.dnbcw.info/php/339659.html pageno: 7.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.