php数组字符串相互转换
2020-05-22 本文已影响0人
风度翩翩的程序猿
废话少说,上代码
首先字符串转数组 => explode()函数
<?php
// 示例 1
$pizza = "piece1 piece2 piece3 piece4 piece5 piece6";
$pieces = explode(" ", $pizza);
echo $pieces[0]; // piece1
echo $pieces[1]; // piece2
// 示例 2
$data = "foo:*:1023:1000::/home/foo:/bin/sh";
list($user, $pass, $uid, $gid, $gecos, $home, $shell) = explode(":", $data);
echo $user; // foo
echo $pass; // *
?>
数组转字符串 => implode ()函数
<?php
$array = array('lastname', 'email', 'phone');
$comma_separated = implode(",", $array);
var_dump(comma_separated ); // 数组被转为字符串
?>
小弟是菜鸟,更多知识等着我们去学,进步使人快乐,一起加油!!!!!!!