数组与字符串之间的相互转换
PHP:
数组转字符串:explode()
$str = "Hello world. It's a beautiful day.";
print_r (explode(" ",$str));
?>
结果: Array(
[0] => Hello
[1] => world.
[2] => It's
[3] => a
[4] => beautiful
[5] => day.
);
字符串转数组:implode()
$array = array('a','b','c');
echo implode($array);
结果: abc
JS,JQ:
数组转换字符串:
arr=[1,2,3,4,5,6,7,8,9];
arr.join("-");
alert(arr);
结果: 1-2-3-4-5-6-7-8-9
字符串转数组:
var str= 1-2-3-4-5-6-7-8-9-
str=substring(0,str.length-1);
str=str.split(",");
alert(str);
结果:[1,2,3,4,5,6,7,8,9];