Skip to content
This repository has been archived by the owner on Jun 20, 2018. It is now read-only.

Commit

Permalink
Merge pull request #11 from robertke/patch-1
Browse files Browse the repository at this point in the history
toValuesArray without keys
  • Loading branch information
italolelis committed May 2, 2016
2 parents 511a185 + 29d548f commit d5179c8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Traits/CommonMutableContainerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,21 @@ public function values()
return new ArrayList($this);
}

/**
* @return array
*/
public function toValuesArray()
{
return $this->toArray();
$arr = [];
foreach ($this as $value) {
if ($value instanceof Iterable) {
$arr[] = $value->toArray();
} else {
$arr[] = $value;
}
}

return $arr;
}

public function toKeysArray()
Expand Down
8 changes: 8 additions & 0 deletions tests/DictionaryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,12 @@ public function testToArray()
$this->coll->addAll($data);
$this->assertEquals($data, $this->coll->toArray());
}

public function testToValuesArray()
{
$dictionary = new Dictionary();
$dictionary->add('key1', 'value1')->add('key2', 'value2');
$expected = ['value1', 'value2'];
$this->assertEquals($expected, $dictionary->toValuesArray());
}
}

0 comments on commit d5179c8

Please sign in to comment.