php - foreach in class: I cannot return all the ele in arr -


Well, I am improving my form generation classes and are stuck in returning all the elements of the country_data array . Only the first two elements are displayed on dropdown options.

Here is the dropdown category:

 // drop down form category class dropdown {function __construct ($ form, $ field_label, $ field_name, $ field_desk, $ dropdown_data, $ locale) { $ This-> form = $ form; $ The-> field_label = $ field_label; $ The-> field_name = $ field_name; $ The-> field_desc = $ field_desc; $ The-> dropdown_data = $ dropdown_data; $ The-> Locale = $ locale; } GetNotRequiredData () {global $ notReAkry; Return $ notReAkry [$ the-> Locale]; } GetValue function () {return $ _POST [$ this-> field_name]; } Function options () {foreach ($ this-> dropdown_data $ key => $ value) {$ options = sprintf ('% s', $ key, $ value); }; } Function dropdown () {return $ select_start = "field_name \"> $ this-> field_desc ". $ This-> option ()." "}} GetLabel () {$ non_req = $ this-> getNotRequiredData (); $ Req = in_array ($ this-> field_name, $ non_req)? ' ': ' *  '; return $ $ this-> field_label? $ Req. $ This-> field_label:' ';} function __to string () {$ id = $ this-> field_name; $ label = $ this-> getLabel (); $ Fields = $ this-> dropdown (); return 'field_name.' "> '. $ '' Label. '$ Area ..'; }} 

And I use additional functions for additional options:

 function generated form ($ lang, $ country_list) {switch ($ lang) {case 'en- US ': // Create a web form $ country fix = new dropdown ($ form,' country ',' form_country ',' - select country - ', $ country_list,' N-US '); break; Case 'FR-FR': // Create RR Web Form Brake; Create a 'Day-Day': // day web form break; Case 'JJ-JP': // Create JA web form break; Default: // Create default web form print ('Foo'); }; } 

And I'm generating, I'm happy at the bottom of the page.

 $ lang = 'en-US'; Generate echo form ($ lang, $ country_list); 

In the last question, a specialist has not mentioned $ Key and $ value in foreach, but I do not understand what I need for more logic here. Yes, I actually have less experience on PHP and just as short on PHP. I need help

Thank you.

All options are available, trying to be repeated by your option function, but always only the first one coming back. Use it instead:

  function options () {$ options = ''; Forex Currency ($ this-> dropdown_data $ key = & gt; $ value) {$ options. = Sprintf ('& lt; option value = "% s">% s ; $ key, $ value); }; Return $ option; }  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -