douying4203 2019-02-14 13:30
浏览 87
已采纳

将数组分隔为逗号分隔的字符串

I want to separate my array into separate strings that all end with a comma.

Array ( [0] => 233d3f9b-3e8e-4e16-ade2-6c165a0324c6 
        [2] => a6c736b0-f3d2-4907-9d36-6b31adeec2d1 
        [3] => 1e693cba-d0ce-4a24-bd75-b834e3f44272 
    )

The purpose of this is so i can pass it to an API. Like this

    'optionUuids' => array(
        $options2,
    ),

The option UUidds can contain multiple values as long its separated by a comma in the end.

I tried solving my problem using implode. Implode adds a comma at the end of each line, but it treats this comma as a string. I want to have multiple option UUids so i would need commas that are actually commas and not strings.

Im having trouble explaining this. This is what i expect:

    'optionUuids' => array(
      233d3f9b-3e8e-4e16-ade2-6c165a0324c6,
      a6c736b0-f3d2-4907-9d36-6b31adeec2d1,
      1e693cba-d0ce-4a24-bd75-b834e3f44272,
    ),
  • 写回答

2条回答 默认 最新

  • doufu9836 2019-02-14 14:09
    关注

    You should use

    'optionUuids' => array_values(
        $options2
    ),
    

    This will give you all the values but with indices starting from zero

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么