php-collection icon indicating copy to clipboard operation
php-collection copied to clipboard

What's the best way to get the map as an array that contains all the keys and values

Open CMCDragonkai opened this issue 10 years ago • 7 comments

Something like

$map->getAll()

I know you can just iterator_to_array($map). But I'm actually extending from the Map class, and I need to return the keys and values as the total array from a child class.

CMCDragonkai avatar Apr 07 '14 09:04 CMCDragonkai

I was vary of adding such a method because it would have made it impossible to allow objects as keys. However since PHP 5.5 now also allows objects as array keys, I think we could add it.

schmittjoh avatar Apr 07 '14 09:04 schmittjoh

Cool, so how will it be done?

CMCDragonkai avatar Apr 07 '14 09:04 CMCDragonkai

It would be great, because that means I don't have to rely on the internals of the Map class. Right now I'm directly accessing $this->elements, and of course that's not part of the public API nor interface.

CMCDragonkai avatar Apr 07 '14 22:04 CMCDragonkai

Can you create a pull request which adds the all() method?

On Tue, Apr 8, 2014 at 12:46 AM, Roger Qiu [email protected] wrote:

It would be great, because that means I don't have to rely on the internals of the Map class. Right now I'm directly accessing $this->elements, and of course that's not part of the public API nor interface.

Reply to this email directly or view it on GitHubhttps://github.com/schmittjoh/php-collection/issues/14#issuecomment-39793198 .

schmittjoh avatar Apr 07 '14 23:04 schmittjoh

Just all or getAll()?

CMCDragonkai avatar Apr 07 '14 23:04 CMCDragonkai

https://github.com/schmittjoh/php-collection/pull/15

CMCDragonkai avatar Apr 07 '14 23:04 CMCDragonkai

Any chance of getting a minor release?

CMCDragonkai avatar Apr 16 '14 09:04 CMCDragonkai