Jump to:

23007 Posts in 11866 Topics by 2828 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: 400 Views
  • SS_Learner
    Avatar
    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
    Avatar
    Forum Moderator
    5464 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.

    400 Views
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.