lithium\util\Collection::offsetSet PHP Method

offsetSet() public method

Assigns a value to the specified offset.
public offsetSet ( string $offset, mixed $value ) : mixed
$offset string The offset to assign the value to.
$value mixed The value to set.
return mixed The value which was set.
    public function offsetSet($offset, $value)
    {
        if ($offset === null) {
            return $this->_data[] = $value;
        }
        return $this->_data[$offset] = $value;
    }

Usage Example

Example #1
0
 /**
  * Tests the `ArrayAccess` interface implementation for manipulating values by direct offsets.
  *
  * @return void
  */
 public function testArrayAccessOffsetMethods()
 {
     $collection = new Collection(array('data' => array('foo', 'bar', 'baz' => 'dib')));
     $this->assertTrue($collection->offsetExists(0));
     $this->assertTrue($collection->offsetExists(1));
     $this->assertTrue($collection->offsetExists('0'));
     $this->assertTrue($collection->offsetExists('baz'));
     $this->assertFalse($collection->offsetExists('2'));
     $this->assertFalse($collection->offsetExists('bar'));
     $this->assertFalse($collection->offsetExists(2));
     $this->assertEqual('foo', $collection->offsetSet('bar', 'foo'));
     $this->assertTrue($collection->offsetExists('bar'));
     $this->assertNull($collection->offsetUnset('bar'));
     $this->assertFalse($collection->offsetExists('bar'));
 }
All Usage Examples Of lithium\util\Collection::offsetSet