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

Commit d5179c8

Browse files
committed
Merge pull request #11 from robertke/patch-1
toValuesArray without keys
2 parents 511a185 + 29d548f commit d5179c8

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/Traits/CommonMutableContainerTrait.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,21 @@ public function values()
1717
return new ArrayList($this);
1818
}
1919

20+
/**
21+
* @return array
22+
*/
2023
public function toValuesArray()
2124
{
22-
return $this->toArray();
25+
$arr = [];
26+
foreach ($this as $value) {
27+
if ($value instanceof Iterable) {
28+
$arr[] = $value->toArray();
29+
} else {
30+
$arr[] = $value;
31+
}
32+
}
33+
34+
return $arr;
2335
}
2436

2537
public function toKeysArray()

tests/DictionaryTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,12 @@ public function testToArray()
191191
$this->coll->addAll($data);
192192
$this->assertEquals($data, $this->coll->toArray());
193193
}
194+
195+
public function testToValuesArray()
196+
{
197+
$dictionary = new Dictionary();
198+
$dictionary->add('key1', 'value1')->add('key2', 'value2');
199+
$expected = ['value1', 'value2'];
200+
$this->assertEquals($expected, $dictionary->toValuesArray());
201+
}
194202
}

0 commit comments

Comments
 (0)