MathPHP\SetTheory\Set::add PHP Method

add() public method

Add an element to the set Does nothing if element already exists in the set.
public add ( mixed $x ) : Set
$x mixed
return Set (this set)
    public function add($x) : Set
    {
        $this->A[$this->getKey($x)] = $x;
        return $this;
    }

Usage Example

Example #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);
 }
All Usage Examples Of MathPHP\SetTheory\Set::add