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, biapar, Willr, Ingo, swaiba, simon_w

Dropdown box poplated from 2-Diamentional array


Reply

2 Posts   467 Views

Avatar
SS_Learner

29 June 2012 at 8:56pm Community Member, 18 Posts

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>

Avatar
Willr

30 June 2012 at 12:27pm Forum Moderator, 5511 Posts

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.