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 Ellery Leung  >  Simple Enumeration  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example file
Class: Simple Enumeration
Implement enumerated types using arrays
Author: By
Last change:
Date: 7 years ago
Size: 1,056 bytes
 

Contents

Class file image Download
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Enum example</title>
</head>
<body>
<?php
include('SimpleEnum.class.php');
$array = array('spring''summer''autumn''winter');

#Create Enum
$eSeason = new SimpleEnum($array);

#Using printValues(): Print in <pre> format for debug purpose
$eSeason->printValues();    

#Using values(): This is the same as $eSeason->printValues();
print '<pre>';    print_r($eSeason->values()); print '</pre>';        

#Using length() to get the number of items in enum
print $eSeason->length().'<br/>';    //Print 4

#Using is() to get the enum
$result $eSeason->is('spring');

#Example of using Enum
if($result == $eSeason->is('spring')){
    print 
'Result is spring'.'<br/>';    //Print
}

if(
$result == $eSeason->is('summer')){
    print 
'Result is summer'.'<br/>';    //Not print
}

?>
</body>
</html>