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.

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

Dropdown box poplated from 2-Diamentional array

Go to End

2 Posts   776 Views


Community Member, 20 Posts

29 June 2012 at 8:56pm

Hi Friends,
I am having a 2-Diamentional array like
[AED] => Array
[Name] => United Arab Emirates Dirham
[Amount] => 3.73723

[ARS] => Array
[Name] => Argentine Peso
[Amount] => 4.60188

I am working on a silverstripe form with a dropdown box.Now i need to add the values of options to the dropdownbox as the keys of array and text as the concatination of key and value pair as example below.
i.e <option value="AED">AED(Argentine Peso)</option>
<option value="ARS">ARS(Argentine Peso)</option>


Forum Moderator, 5523 Posts

30 June 2012 at 12:27pm

All you need to do is iterate through your current array and build a new one.

$input = // your current array
$output = array(); // new array

foreach($input as $k => $v) {
$output[$k] = $k . ' ('. $v['Name'] .')';

Then use $output as your source in the dropdown field.