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.