控制器中的codeigniter中的数组到字符串转换错误

$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

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);

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).

$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;