From f00d6670efef1fb5b2ff297fd93c8b57ab24bbf0 Mon Sep 17 00:00:00 2001 From: Robert Kel Date: Sun, 1 May 2016 23:32:24 +0200 Subject: [PATCH 1/2] toValuesArray without keys If let's say we have Dictionary with one element: key -> 111:11:11 and value -> object and when we need to do toValuesArray i expect to get only values in that array but not key values array it might be another one for that purpose like toKeyValuesArray (toArray does this) to keep keys from Dictionary --- src/Traits/CommonMutableContainerTrait.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Traits/CommonMutableContainerTrait.php b/src/Traits/CommonMutableContainerTrait.php index ccaca32..4f0d204 100644 --- a/src/Traits/CommonMutableContainerTrait.php +++ b/src/Traits/CommonMutableContainerTrait.php @@ -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() From 29d548f0682b3d5162509202e9376834d34ab511 Mon Sep 17 00:00:00 2001 From: Robert Kel Date: Mon, 2 May 2016 12:08:23 +0200 Subject: [PATCH 2/2] Simple test --- tests/DictionaryTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/DictionaryTest.php b/tests/DictionaryTest.php index 427bce1..b797b61 100755 --- a/tests/DictionaryTest.php +++ b/tests/DictionaryTest.php @@ -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()); + } }