Jump to:

23487 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Dropdown box poplated from 2-Diamentional array

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

Page: 1
Go to End
Author Topic: 457 Views
  • SS_Learner
    Community Member
    18 Posts

    Dropdown box poplated from 2-Diamentional array Link to this post

    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>

  • Willr
    Forum Moderator
    5508 Posts

    Re: Dropdown box poplated from 2-Diamentional array Link to this post

    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.

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.