Query: arrayaccess
OS: php
Section: 3
Format: Original Unix Latex Style Formatted with HTML and a Horizontal Scroll Bar
ARRAYACCESS(3) 1 ARRAYACCESS(3) The ArrayAccess interfaceINTRODUCTIONInterface to provide accessing objects as arrays.INTERFACE SYNOPSISArrayAccess ArrayAccess Methods o abstractpublic boolean ArrayAccess::offsetExists (mixed $offset) o abstractpublic mixed ArrayAccess::offsetGet (mixed $offset) o abstractpublic void ArrayAccess::offsetSet (mixed $offset, mixed $value) o abstractpublic void ArrayAccess::offsetUnset (mixed $offset) Example #1 Basic usage <?php class obj implements ArrayAccess { private $container = array(); public function __construct() { $this->container = array( "one" => 1, "two" => 2, "three" => 3, ); } public function offsetSet($offset, $value) { if (is_null($offset)) { $this->container[] = $value; } else { $this->container[$offset] = $value; } } public function offsetExists($offset) { return isset($this->container[$offset]); } public function offsetUnset($offset) { unset($this->container[$offset]); } public function offsetGet($offset) { return isset($this->container[$offset]) ? $this->container[$offset] : null; } } $obj = new obj; var_dump(isset($obj["two"])); var_dump($obj["two"]); unset($obj["two"]); var_dump(isset($obj["two"])); $obj["two"] = "A value"; var_dump($obj["two"]); $obj[] = 'Append 1'; $obj[] = 'Append 2'; $obj[] = 'Append 3'; print_r($obj); ?> The above example will output something similar to: bool(true) int(2) bool(false) string(7) "A value" obj Object ( [container:obj:private] => Array ( [one] => 1 [three] => 3 [two] => A value [0] => Append 1 [1] => Append 2 [2] => Append 3 ) ) PHP Documentation Group ARRAYACCESS(3)
Related Man Pages |
---|
var_export(3) - php |
splobjectstorage(3) - php |
iterator(3) - php |
serializable(3) - php |
splstack(3) - php |
Similar Topics in the Unix Linux Community |
---|
make command failed for target 'obj/gp_unix.o' |
awk command not woking |
PHP code to Perl plx |
Append Spaces to a string |
PHP: declared variables, strlen vs isset |