字符串式数组和数组式字符串
var_export — 输出或返回一个变量的字符串表示;
eval — 把字符串作为PHP代码执行;
//定义一个数组
$a=array(
'test'=>'tesq0',
1=>'tesq1',
2=>'tesq2',
3=>'tesq3',
4=>'tesq4',
5=>'tesq5',
);
数组转换为字符串
$x=var_export($a,true);
var_dump($x);
/*
string(110) "array (
'test' => 'tesq0',
1 => 'tesq1',
2 => 'tesq2',
3 => 'tesq3',
4 => 'tesq4',
5 => 'tesq5',
)"
*/
字符串转换为数组
@eval("\$array = $x;");
var_dump($array);
/*
array(6) {
["test"]=>
string(5) "tesq0"
[1]=>
string(5) "tesq1"
[2]=>
string(5) "tesq2"
[3]=>
string(5) "tesq3"
[4]=>
string(5) "tesq4"
[5]=>
string(5) "tesq5"
}
*/

浙公网安备 33010602011771号