PHP 数组转化成字符串,该如何处理

WBOY
Release: 2016-06-13 12:08:34
Original
1039 people have browsed it

PHP 数组转化成字符串
[b]Array ( [0] => 0 [1] => 1[2]=>1)这种数组怎么转化成array(0,1,1)
或者a=1,1,0怎么转化成array(1,1,0)[/b]希望大家帮帮忙
------解决思路----------------------
Array ( [0] => 0 [1] => 1[2]=>1),就是array(0,1,1),只不过是因为打印出来,自动加了键名(下标),默认就是从0开始的
第二个问题,你是想要这样?

<br />$a='1,1,0';<br /><br />$new=explode(',',$a);<br />echo "<pre class="brush:php;toolbar:false">";<br />print_r($new);<br />echo "
Copy after login
";
/*
Array
(
[0] => 1
[1] => 1
[2] => 0
)
*/


------解决思路----------------------
PHP数组转化字符串问题
//应用explode()函数将字符串转换成数组
$str = "PHP、JSP、ASP"; //定义一个字符串
$strs = explode("、", $str); //应用explode()函数将字符串转换成数组
print_r($strs); //输出数组元素
?>
//直接为数组元素赋值
$array[1]="阿";
$array[2]="里";
$array[3]="巴";
$array[4]="巴";
print_r($array);        //输出所创建数组的结构
?>

------解决思路----------------------
array_values($arr);
------解决思路----------------------
字符串 1,1,0 需要按数字存入数组 就用explode()
如果是需要一种用字符串/文件保存数组的方式 就用serialize() 和unserialize()

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template