字符串转入二维数组
程序员文章站
2024-04-03 13:20:34
...
字符串转为二维数组
$str = array ( 'digest' => '2012', ), 1 => array ( 'digest' => '2011', ), 2 => array ( 'digest' => '2010', ), 3 => array ( 'digest' => '2009', ), 4 => array ( 'digest' => '2008', ), 5 => array ( 'digest' => '2007', ), ); ?>
需要转成
Array
(
[0] => Array
(
[digest] => 2012
)
[1] => Array
(
[digest] => 2011
)
[2] => Array
(
[digest] => 2010
)
[3] => Array
(
[digest] => 2009
)
[4] => Array
(
[digest] => 2008
)
[5] => Array
(
[digest] => 2007
)
)
求高人帮忙啊
------解决方案--------------------
你字符串是这样的吗?
$str = "array ( 'digest' => '2012'), 1 => array ( 'digest' => '2011' )........"
是的话
$str = array ( 'digest' => '2012', ), 1 => array ( 'digest' => '2011', ), 2 => array ( 'digest' => '2010', ), 3 => array ( 'digest' => '2009', ), 4 => array ( 'digest' => '2008', ), 5 => array ( 'digest' => '2007', ), ); ?>
需要转成
Array
(
[0] => Array
(
[digest] => 2012
)
[1] => Array
(
[digest] => 2011
)
[2] => Array
(
[digest] => 2010
)
[3] => Array
(
[digest] => 2009
)
[4] => Array
(
[digest] => 2008
)
[5] => Array
(
[digest] => 2007
)
)
求高人帮忙啊
------解决方案--------------------
你字符串是这样的吗?
$str = "array ( 'digest' => '2012'), 1 => array ( 'digest' => '2011' )........"
是的话
- PHP code
'2012'), 1 => array ( 'digest' => '2011' )"; $arr=explode(',',$str); $temp=array(); foreach($arr as $key=>$value) { $arr_temp=explode("'",$value); $real_value=$arr_temp[3]; $temp[$key]['digest'] = $real_value; } print_r($temp); ?>相关文章
相关视频