PHP Classes

File: example.php

Recommend this page to a friend!
  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: 16 years ago
Size: 1,056 bytes


Class file image Download
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Enum example</title>
$array = array('spring', 'summer', 'autumn', 'winter');

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

#Using printValues(): Print in <pre> format for debug purpose

#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')){
'Result is spring'.'<br/>'; //Print

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