![]() |
SOLVED: PHP Array Help Needed. - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: SOLVED: PHP Array Help Needed. (/showthread.php?tid=29521) |
SOLVED: PHP Array Help Needed. - El Forum - 04-12-2010 [eluser]Deep Arora[/eluser] I have following code in my model: Quote: if ($query->num_rows() > 0) It returns array like this: Code: Array ( [0] => Array ( [FLAG_CHOICE] => Y ) [1] => Array ( [FLAG_CHOICE] => N ) ) In my controller, I am receiving the value returned as array above. Now, I want to form an array out of the above array as: Code: $options = array( which is a single dimensional array.. How do I do that? I suck at handling arrays sometimes, so need a little helping hand ![]() SOLVED: PHP Array Help Needed. - El Forum - 04-12-2010 [eluser]danmontgomery[/eluser] Array keys must be unique, you can't have the array you're describing. SOLVED: PHP Array Help Needed. - El Forum - 04-12-2010 [eluser]Deep Arora[/eluser] Hmmm..then how can we use form_dropdown function? Code: form_dropdown('fieldname', $field_value, 'selectedvaluearray') The $field_value expects single dimension array. And I am getting $field_value array from a table..and when we get records from table, they are returned back in 2-dimension array, yes? SOLVED: PHP Array Help Needed. - El Forum - 04-13-2010 [eluser]mddd[/eluser] There are multiple things going on here. First, noctrum is correct: you can't have an array containing duplicate keys. Second, yes the input for the form_dropdown is as simple array, like Code: $form_values = array( The problem here is that you are creating the two dimensional array yourself! You are adding options, but each option is an array! Code: $options[] = array( .... ); You should use something like Code: foreach ($query->result() as $row) Then the result is a simple array like shown above. SOLVED: PHP Array Help Needed. - El Forum - 04-13-2010 [eluser]Deep Arora[/eluser] Worked like a charm....thanks ![]() |