add() 공개 메소드

Add an element to the set Does nothing if element already exists in the set.
public add ( mixed $x ) : Set
$x mixed
리턴 Set (this set)
예제 #1
0
 public function testFluentInterface()
 {
     $A = new Set();
     $A->add(1)->add(2)->add(3)->remove(2)->add(4)->remove(1)->addMulti([5, 6, 7])->add(new Set([1, 2, 3]))->removeMulti([5, 6]);
     $B = new Set([3, 4, 7, new Set([1, 2, 3])]);
     $this->assertEquals($B, $A);
 }
예제 #2
0
 /**
  * When adding resources to a set, the key becomes to the resource ID.
  * The resource is stored as is as the value.
  */
 public function testAddWithResources()
 {
     $set = new Set();
     $fh = fopen(__FILE__, 'r');
     $set->add($fh);
     $set->add($fh);
     // Should only get added once
     $this->assertEquals(1, count($set));
     $this->assertEquals(1, count($set->asArray()));
     $resources = 0;
     foreach ($set as $key => $value) {
         if (is_resource($value)) {
             $resources++;
             $vector_key = 'Resource(' . strval($value) . ')';
             $this->assertEquals($vector_key, $key);
             $this->assertEquals($fh, $value);
         }
     }
     // There should have been one resource
     $this->assertEquals(1, $resources);
 }