php 字符串 转 数组
时间: 2023-10-20 11:33:57 浏览: 81
PHP 把字符串转换为数组支持中文
在PHP中,可以使用explode函数将字符串转换为数组。该函数需要两个参数,第一个参数是分隔符,用于指定在哪个字符处进行分割,第二个参数是要进行分割的字符串。例如,如果要将字符串"hello1,hello2,hello3,hello4,hello5"按逗号分割为数组,可以使用以下代码:
```
$source = "hello1,hello2,hello3,hello4,hello5";
$array = explode(',', $source);
```
在上述代码中,我们将逗号作为分隔符,将$source字符串分割成了一个包含"hello1","hello2","hello3","hello4"和"hello5"的数组$array。现在,你可以通过引用数组的索引来访问和操作数组中的元素。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [PHP实现多维数组转字符串和多维数组转一维数组的方法](https://download.csdn.net/download/weixin_38691482/13729533)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [PHP从数组中随机选取几个值组成新的字符串(输出字符串非数组)](https://download.csdn.net/download/xiaoyuejie/82719227)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [php中利用explode函数分割字符串到数组](https://download.csdn.net/download/weixin_38611877/13731546)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文