Revision: 12345
Updated Code
at March 11, 2009 16:35 by dbug13
Updated Code
<?php
class Set
{
protected $_storage_array;
function __constructor()
{
$this->_storage_array = array();
}
function add($value)
{
$this->_storage_array[$value] = $value;
}
function hasValue($value)
{
return in_array($value, array_keys($this->_storage_array));
}
function toArray()
{
return array_keys($this->_storage_array);
}
}
$data = new Set;
$data->add("Sarah");
$data->add("Jamie");
$data->add("Phil");
$data->add("Jamie");
print("Has Value Jamie? " . ($data->hasValue("Jamie") ? 'true' : 'false')) . PHP_EOL;
print_r($data->toArray());
/*
Returns the following:
Has Value Jamie? true
Array
(
[0] => Sarah
[1] => Jamie
[2] => Phil
)
*/
?>
Revision: 12344
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at March 11, 2009 16:28 by dbug13
Initial Code
<?php
class Set
{
protected $_storage_array;
function __constructor()
{
$this->_storage_array = array();
}
function add($value)
{
$this->_storage_array[$value] = $value;
}
function hasValue($value)
{
return in_array($value, array_keys($this->_storage_array));
}
function toArray()
{
return array_keys($this->_storage_array);
}
}
$data = new Set;
$data->add("Sarah");
$data->add("Jamie");
$data->add("Phil");
$data->add("Jamie");
print("Has Value Jamie? " . ($data->hasValue("Jamie") ? 'true' : 'false')) . PHP_EOL;
print_r($data->toArray());
?>
Initial URL
Initial Description
Initial Title
a Set class that maintains an array of unique items
Initial Tags
class, php, textmate
Initial Language
PHP