PHP數(shù)組轉(zhuǎn)字符串與PHP字符串轉(zhuǎn)數(shù)組的相關(guān)方法解析
我們今天為大家介紹的PHP數(shù)組轉(zhuǎn)字符串與PHP字符串轉(zhuǎn)數(shù)組的代碼將會用到函數(shù)implode() 和函數(shù)explode() 。其中implode() 函數(shù)是用來數(shù)組轉(zhuǎn)字符串時(shí)用,而explode() 函數(shù)則是用來處理字符串轉(zhuǎn)數(shù)組的。
#t#PHP數(shù)組轉(zhuǎn)字符串 implode()
- <?php
- $vegetables[0] = "corn";
- $vegetables[1] = "broccoli";
- $vegetables[2] = "zucchini";
- $text = implode(",", $vegetables);
- echo $text;
- ?>
運(yùn)行結(jié)果
corn,broccoli,zucchini
2 PHP字符串轉(zhuǎn)數(shù)組 explode()
- <?php
- $text = "corn, broccoli, zucchini";
- $vegetables = explode(", ", $text);
- print_r($vegetables);
- ?>
運(yùn)行結(jié)果:
- Array
- (
- [0] => corn
- [1] => broccoli
- [2] => zucchini
- )
以上兩段代碼就是我們向大家介紹的關(guān)于PHP數(shù)組轉(zhuǎn)字符串和PHP字符串轉(zhuǎn)數(shù)組的相關(guān)代碼。