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

报告相同问题?