Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Convert an ArrayData object into a normal PHP array?


Go to End


4 Posts   2729 Views

Avatar
purplespider

Community Member, 89 Posts

16 July 2010 at 6:26am

How can I convert an ArrayData object into a normal PHP array?

I have a function that outputs an ArrayData object so that I can display it in a template, but I also have another function that needs to iterate through the array and check it's values with another array, this I cannot do unless the ArrayData is changed into a normal array.

Thanks
James

Avatar
zenmonkey

Community Member, 545 Posts

16 July 2010 at 6:47am

Avatar
Willr

Forum Moderator, 5523 Posts

16 July 2010 at 9:52am

Ah interesting, you can set the array(), but no methods in ArrayData to get the raw array back out, doesn't appear like its possible to simply get an array. You can however loop over the ArrayData object using the Viewable Iterator (http://api.silverstripe.org/2.4/sapphire/view/ViewableData.html#methodgetIterator). Haven't used that too much.

I've added a getArray() to ArrayData to make something like this easier. See http://open.silverstripe.org/changeset/108012

You can either apply that change to your copy of SS, download the latest 2.4 version from svn (daily builds tomorrow) or wait till 2.4.1

Avatar
purplespider

Community Member, 89 Posts

18 July 2010 at 5:04am

Amazing! Thank you very much Willr, works great!