我們今天為大家介紹的PHP數組轉字符串 implode()
- <?php
- $vegetables[0] = "corn";
- $vegetables[1] = "broccoli";
- $vegetables[2] = "zucchini";
- $text = implode(",", $vegetables);
- echo $text;
- ?>
運行結果
corn,broccoli,zucchini
2 PHP字符串轉數組 explode()
- <?php
- $text = "corn, broccoli, zucchini";
- $vegetables = explode(", ", $text);
- print_r($vegetables);
- ?>
運行結果:
- Array
- (
- [0] => corn
- [1] => broccoli
- [2] => zucchini
- )
以上兩段代碼就是我們向大家介紹的關於PHP數組轉字符串和PHP字符串轉數組的相關代碼。