1
$data = array('first_name' => $this->input->post('fname'),
'middle_name' => $this->input->post('mname'),

'last_name' => $this->input->post('lname'),
'email_name' => $this->input->post('email'),
'pwd_name' => $this->input->post('pwd'),

    'cno_name' => $this->input->post('cno'),
    'gender_name' => $this->input->post('gender'),
    'country_name' => $this->input->post('country'),
    'lang_name' => $this->input->post('lang')

);
            echo $data;

i want to echo or print $data, but it showing error Severity: Notice

Message: Array to string conversion

2

3 Answers 3

3

Method 1

foreach($data as $key => $val)
    echo($key.' => '.(is_array($val)?implode(',', $val):$val).'<br>');

Method 2

var_dump($data);

Method 3

print_r($data);
Sign up to request clarification or add additional context in comments.

2 Comments

lang_name contain multiselect, all values are printing except lang_name.How can i print this variable also? <input type="checkbox" name="lang[]" value="Telugu" /> Telugu<br> <input type="checkbox" name="lang[]" value="Hindi" /> Hindi<br> <input type="checkbox" name="lang[]" value="English" /> English<br>
Which method are you using?
0

1) your trying to echo the array variable ($data)

2) your not able to use echo for array variable

solution:

3) you can use var_dump($data) or print_r($data).

1 Comment

lang_name contain multiselect, all values are printing except lang_name.How can i print this variable also? <input type="checkbox" name="lang[]" value="Telugu" /> Telugu<br> <input type="checkbox" name="lang[]" value="Hindi" /> Hindi<br> <input type="checkbox" name="lang[]" value="English" /> English<br>
0
$data = array('first_name' => $this->input->post('fname'),
'middle_name' => $this->input->post('mname'),

'last_name' => $this->input->post('lname'),
'email_name' => $this->input->post('email'),
'pwd_name' => $this->input->post('pwd'),

    'cno_name' => $this->input->post('cno'),
    'gender_name' => $this->input->post('gender'),
    'country_name' => $this->input->post('country'),
    'lang_name' => $this->input->post('lang')

);

Now There is foreach loop in php. You have to traverse the array.

    foreach($data  as $key => $value)
    {
      echo $key." has the value". $value;
    }

If you simply want to add commas between values, consider using implode

    $string=implode(",",$data);
    echo $string;

5 Comments

<input type="checkbox" name="lang[]" value="Telugu" /> Telugu<br> <input type="checkbox" name="lang[]" value="Hindi" /> Hindi<br> <input type="checkbox" name="lang[]" value="English" /> English<br> in above array, lang_name contain multiselect, in foreach loop its not getting print
@Danush you could change the field name.
lang_name contain multiselect, all values are printing except lang_name.How can i print this variable also? <input type="checkbox" name="lang[]" value="Telugu" /> Telugu<br> <input type="checkbox" name="lang[]" value="Hindi" /> Hindi<br> <input type="checkbox" name="lang[]" value="English" /> English<br>
Get them like this: substr(implode(', ', $this->input->post('lang')), 0)
you can also use like this $this->input->post('lang'); It will be an array, the same thing as $_POST['lang']. Example foreach ($this->input->post('lang') as $key => $value) { echo "Index {$key}'s value is {$value}."; } Unfortunately, if you need to access a specific index, you'll have to lang it to a variable first or use $_POST instead of $this->input->post(). Example: $assign = $this->input->post('lang'); echo $assign[0]; // First value echo $_POST['lang'][0];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.