我有数据“ test1 @ gmail.com,test2 @ gmail.com”如何使结果看起来像这样

时间:2019-03-07 01:30:45

标签: php codeigniter

我的代码:

  $read = $this->m_crud->read_data("subscribe","*");

   $newData=array();

      foreach($read as $key){
          $newData[] = $key["email"];
       }

    $to = implode(",",$newData);

    echo json_encode($to)

结果:

"test1@gmail.com, test2@gmail.com"

问题:如何使结果看起来像这样:

"test1@gmail.com", "test2@gmail.com"

1 个答案:

答案 0 :(得分:0)

只需删除implode()函数。implode()是PHP中的内置函数,用于连接数组的元素。建议将implode()的分隔符(,)参数始终使用两个参数以实现向后兼容。

<?php 
   $read = $this->m_crud->read_data("subscribe","*");

   $newData=array();

      foreach($read as $key){
          $newData[] = $key["email"];
       }
    echo json_encode($newData);
?>