php如何将数组转化成字符串

Life is short , play more!
本文来自lihao's Blog,转载请注明。

可以使用implode和join函数, impolode这个函数有3种.

i)    string implode ( $separator, $array)

ii)    string implode (  $array)

iii)    string implode ( $array, $separator)

示例一:

<?php

$array1=$array2=array(“CPU”,“VDU”,“KEYBOARD”);

$array1=implode($array1,“,”);

print_r($array1);

echo“<br/>”;

$array1=implode(“+”,$array2);

print_r($array1);

?>

示例一输出:

CPU,VDU,KEYBOARD
CPU+VDU+KEYBOARD

join() function is an alias for implode(), output will be same as implode() function, example of join() is as follows:

 

示例二:

<?php

$array1=$array2=array(“CPU”,“VDU”,“KEYBOARD”);

$array1=join($array1,“,”);

print_r($array1);

echo“<br/>”;

$array1=join(“+”,$array2);

print_r($array1);

?>

示例二输出:

CPU,VDU,KEYBOARD
CPU+VDU+KEYBOARD


发表评论

电子邮件地址不会被公开。 必填项已用*标注