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

danush
  • 13
  • 2

3 Answers3

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);
sg-
  • 2,196
  • 1
  • 15
  • 16
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).

JYoThI
  • 11,977
  • 1
  • 11
  • 26
  • lang_name contain multiselect, all values are printing except lang_name.How can i print this variable also? Telugu
    Hindi
    English
    – danush May 28 '16 at 11:53
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;
Gorakh Yadav
  • 304
  • 5
  • 19
  • Telugu
    Hindi
    English
    in above array, lang_name contain multiselect, in foreach loop its not getting print
    – danush May 28 '16 at 11:50
  • @Danush you could change the field name. – Gorakh Yadav May 28 '16 at 11:50
  • lang_name contain multiselect, all values are printing except lang_name.How can i print this variable also? Telugu
    Hindi
    English
    – danush May 28 '16 at 11:53
  • Get them like this: substr(implode(', ', $this->input->post('lang')), 0) – Gorakh Yadav May 28 '16 at 11:57
  • 1
    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]; – Gorakh Yadav May 28 '16 at 12:01