PHP数组和字符串转换方法

1 数组转字符串 implode()


$vegetables[0] = "corn";

$vegetables[1] = "broccoli";

$vegetables[2] = "zucchini";

$text = implode(",", $vegetables);

echo $text;

?>

运行结果

corn,broccoli,zucchini

2 字符串转数组 explode()


$text = "corn, broccoli, zucchini";

$vegetables = explode(", ", $text);

print_r($vegetables);

?>

运行结果:

Array

(

[0] => corn

[1] => broccoli

[2] => zucchini

)

你可能感兴趣的:(PHP数组和字符串转换方法)