Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of NHM TAnveer Hossain Khan  >  PHP Collection Class  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Collection Class
Manages collections of objects
Author: By
Last change: Example script
Date: 2005-03-19 21:12
Size: 1,233 bytes
 

Contents

Class file image Download
<?php
/**
  PHPCollection example script
*/
/* Include */
require 'base.class.php';
require 
'collection.class.php';

/* Create an example object */
class ExampleObject extends Base {
  var 
$name;
  
  function 
ExampleObject($s) {
    
$this->name=$s;
  }
  
  function 
setName($s) {
    
$this->name=$s;
  }
  
  function 
getName() {
    return 
$this->name;
  }
}

/* collection */
$coll=new Collection();

/* add to collection class */
$coll->add(new ExampleObject("Tanveer"));
$coll->add(new ExampleObject("Hasan"));

/* Iterate */
$it=$coll->iterator();

/* retrive object */
while($it->hasNext()) {
  
$obj=$it->next();
  echo 
"<b>Name: </b>".$obj->getName()."<br />";
}

/**********************************************************
 **             Without declaring Object                 **
 **                                                      **
 **********************************************************/
 
$coll2=new Collection();
 
 
$coll2->add("My first String");
 
$coll2->add("My second string");
 
 
/* iterator */
 
$it=$coll2->iterator();
 
 
/* fetch */
 
while($it->hasNext()) {
   
$obj=$it->next();
   echo 
"<b>String: </b>".$obj->getValue()."<br />";
 }

?>