Sitellite Application Framework
Class Tree         Index         All Elements

Class: Alt

Source Location: Program_Root/Misc/Alt.php

Class Overview


Alt is a tiny class that alternates through a list of values each time you call the next () method. When it gets to the end of the list, the pointer is reset to the beginning.


Author(s)

Version

  • 1.2, 2002-11-13, $Id: Alt.php,v 1.2 2005/07/06 15:30:56 lux Exp $

Copyright

  • Copyright (C) 2001-2003, Simian Systems Inc.

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 92]
Alt is a tiny class that alternates through a list of values each time you call the next () method. When it gets to the end of the list, the pointer is reset to the beginning.

This class is a little redundant, as a simple array would usually suffice, but the Object Oriented syntax is nicer, and our original inspiration for this class was a two element array of background colours for table rows. The equivalent using an array still required an if statement, which this eliminates.

New in 1.2:

  • Added a reset() method.

1 <?php
2
3 $c = new Alt ('odd', 'even');
4
5 while (...) {
6 echo $c->next ();
7 }
8
9 --
10
11 The equivalent using a single variable:
12
13 $c = 'odd';
14
15 while (...) {
16 echo $c;
17 if ($c == 'odd') {
18 $c = 'even';
19 } else {
20 $c = 'odd';
21 }
22 }
23
24 --
25
26 The equivalent using an array:
27
28 $c = array ('odd', 'even');
29 $i = 0;
30
31 while (...) {
32 echo $c[$i];
33 if ($i >= count ($c)) {
34 $i = 0;
35 }
36 }
37
38 Using arrays, the next(), current(), each(), end(), etc. functions are
39 not appropriate when the alternating values are not the focus of the
40 loop, but are still required to change.
41
42 ?>




Tags:

access:  public
version:  1.2, 2002-11-13, $Id: Alt.php,v 1.2 2005/07/06 15:30:56 lux Exp $
license:  http://www.sitellite.org/index/license
copyright:  Copyright (C) 2001-2003, Simian Systems Inc.
author:  John Luxford <mailto:lux@simian.ca>


[ Top ]


Class Variables

$vals =

[line 99]

List of values to alternate between.



Tags:

access:  public

Type:   mixed


[ Top ]



Class Methods


constructor Alt [line 128]

Alt Alt( mixed $vals, [mixed $val2 = ''], [mixed $val3 = ''])

Constructor method. If the first parameter is an array, it is used to set the $vals property. If not, up to three parameters can be passed, which are fed into the $vals property array.



Tags:

access:  public


Parameters:

mixed   $vals  
mixed   $val2  
mixed   $val3  

[ Top ]

method next [line 151]

mixed next( )

Advances the internal counter and returns the next value.



Tags:

access:  public


[ Top ]

method reset [line 166]

void reset( )

Returns the internal counter to 0 and returns nothing.



Tags:

access:  public


[ Top ]


Copyright © 2007, SIMIAN systems Inc.
All rights reserved. Privacy policy
Documentation generated on Tue, 13 Feb 2007 17:16:43 -0600 by Sitellite AppDoc and phpDocumentor 1.2.2