Yohanne Posted September 9, 2016 Share Posted September 9, 2016 Hi coders, i just want to display the each value of input text but i don't get it, any advice where i go wrong.. no database required. <input type='text' name = 'val1[]' value='asasas'> <input type='text' name = 'val2[]' value='asasas'> <input type='text' name = 'val1[]' value='sdsddd'> <input type='text' name = 'val2[]' value='sdsdsd'> $value1 = $this->input->post('val1'); $value2 = $this->input->post('val2'); $array = array(value1, value2); echo $comma_separated = implode(",", $array); Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted September 9, 2016 Share Posted September 9, 2016 implode() isn't recursive. When you apply it to an array of arrays, you get nonsense. Simply pass each array individually: <?php $values1 = ['foo', 'bar']; $values2 = ['qux', 'quux']; echo implode(',', $values1).' -- '.implode(',', $values2); Quote Link to comment Share on other sites More sharing options...
Yohanne Posted September 9, 2016 Author Share Posted September 9, 2016 (edited) i already trying here, but don't get the logic.. and how do i get the value of input text. i mean is, where is the input text value here Edited September 9, 2016 by Yohanne Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted September 9, 2016 Share Posted September 9, 2016 I have given you an example of how to correctly display two arrays of values. Where those arrays come from is entirely irrlevant. If you don't know how to get POST parameters in CodeIgniter, you're in the wrong forum. I can move your thread to the frameworks section. Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted September 9, 2016 Share Posted September 9, 2016 (edited) Do you know if the value variables (eg. $value1) contain arrays? You could check using code like this: echo '<pre>' . print_r($value1, true) . '</pre>'; Also note that the following line is missing dollar signs before the value variables: $array = array(value1, value2); And with the following line, do you expect a comma-separated list of both $value1 and $value2? echo $comma_separated = implode(",", $array); In other words, do you expect the following output: asasas,sdsddd,asasas,sdsdsd If so, you could use array_merge() to combine the arrays. More information can be found here: http://php.net/manual/en/function.array-merge.php Note that the following line just creates an array of arrays: $array = array_merge($value1, $value2); Edited September 9, 2016 by cyberRobot Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.