dreamwind1985 2015-03-12 02:41
浏览 21
已采纳

php数组到json数组(使用sendgrid)

I would like to use a php array in this example rather than have to hard code the array. How would I use a php to replace this json example?

Here the working code with the json array:

$json_string = array(

  'to' => array(
    'example1@sendgrid.com', 'example2@sendgrid.com'
  ),
  'category' => 'test_category'
);

But I need to replace the 'to' values with my own php array. I tried this but it doesn't work:

$myEmails[] = array('emailOne@gmail.com','email2@gmail.com');
$json_string = array(

  'to' => $myEmails, /// DOES NOT WORK
  'category' => 'test_category'
);

What code for the json could I use to add my own php array values here? In short I am trying to send multiple emails using sendgrid but I thought this might work but its not.

  • 写回答

1条回答 默认 最新

  • drdyf42880 2015-03-12 02:44
    关注

    Just get rid of the square braces [] after $myEmails, and everything should work:

    <?php 
      $myEmails = array('emailOne@gmail.com','email2@gmail.com');
      $json_string = array(
        'to' => $myEmails, /// DOES NOT WORK
        'category' => 'test_category'
      );
      var_dump($json_string);
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 bywave配置文件写入失败
  • ¥20 基于Simulink的ZPW2000轨道电路仿真
  • ¥15 pycharm找不到在环境装好的opencv-python
  • ¥15 在不同的执行界面调用同一个页面
  • ¥20 基于51单片机的数字频率计
  • ¥50 M3T长焦相机如何标定以及正射影像拼接问题
  • ¥15 keepalived的虚拟VIP地址 ping -s 发包测试,只能通过1472字节以下的数据包(相关搜索:静态路由)
  • ¥15 Mabatis查询数据
  • ¥15 想知道lingo目标函数中求和公式上标是变量情况如何求解
  • ¥15 关于E22-400T22S的LORA模块的通信问题