字符串为array('name'=>'tom','pw'=>'hello','email'=>'[email protected]')
如何转为数组array('name'=>'tom','pw'=>'hello','email'=>'[email protected]'),
只改变类型(用php,要有较高转换效率),求解,谢谢
如何转为数组array('name'=>'tom','pw'=>'hello','email'=>'[email protected]'),
只改变类型(用php,要有较高转换效率),求解,谢谢
[User:root Time:08:49:42 Path:/home/liangdong/php]$ php arr.php
Array
(
[name] => tom
[pw] => hello
[email] => [email protected]
)
[User:root Time:08:49:42 Path:/home/liangdong/php]$ cat arr.php
<?php
$str = "array('name'=>'tom','pw'=>'hello','email'=>'[email protected]');";
eval('$arr = ' . $str);
print_r($arr);
?>
$arr=eval("return $s;");
var_dump($arr);
学习了,刚才还在看:
eval() returns NULL unless return is called in the evaluated code, in which case the value passed to return is returned. If there is a parse error in the evaluated code, eval() returns FALSE and execution of the following code continues normally. It is not possible to catch a parse error in eval() using set_error_handler().这句话的意思,这下了了。
输出结果是:array(3) { ["name"]=> string(3) "tom" ["pw"]=> string(5) "hello" ["email"]=> string(15) "[email protected]" }
怎么把string(3) string(5) string(15)这些信息去掉啊?
foo($arr);
function foo($ar=array()){
.........................
}