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

Can I edit objects already in an ArrayList?


Go to End


961 Views

Avatar
old bluffer

Community Member, 2 Posts

28 June 2017 at 5:12am

Hi, I have an ArrayList which I use to collect data objects from an external source and render them in my Silverstripe template.
But I now find that I need to edit some of the objects in the list, after the list is populated.

If it were an array, I would just do something like

                $key = array_search($id,$my_array);
                if ($key !== false){
                    $my_array[$key]->my_field = $new_value;
                }

...but I can't figure out the syntax to do this in an ArrayList.

Is it possible, or do I need to refactor, to do my edits prior to building the ArrayList?

Cheers!