Jump to content

Recommended Posts

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);
Link to comment
https://forums.phpfreaks.com/topic/302116-post-array/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/302116-post-array/#findComment-1537213
Share on other sites

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 by cyberRobot
Link to comment
https://forums.phpfreaks.com/topic/302116-post-array/#findComment-1537229
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.