控制器中代码点火器中的数组到字符串转换错误

array to string conversion error in codeginiter in controller

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

我想回显或打印 $data,但它显示错误严重性:注意

消息:数组到字符串的转换

方法一

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

方法二

var_dump($data);

方法三

print_r($data);

1) 你试图回应 array 变量 ($data)

2) 你不能对数组变量

使用echo

解法:

3) 您可以使用 var_dump($data)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')

);

现在 php 中有 foreach 循环。你得遍历数组。

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

如果您只想在值之间添加逗号,请考虑使用 implode

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