将字符串(数组...)转换为数组php?

时间:2010-12-16 15:20:02

标签: php

echo $_POST['var'];

Array(0,Array(0=>;sdfds)),Array(0,Array(1=>;sa;d)),Array(1,Array(0=>;xx;xxx;xxxs))



  $new_str = str_replase(")),A","))|A",$_POST['var']);

  $first_arr =  explode("|",$new_str);


print_r($first_arr);

输出

Array
(
[0] => Array(0,Array(0=>;sdfds)) // infact [0] => "Array(0,Array(0=>;sdfds))" not array of array
[1] => Array(0,Array(1=>;sa;d))  // [1] => "Array(0,Array(1=>;sa;d))" not array of array
[2] => Array(1,Array(0=>;xx;xxx;xxxs)) //[2] => "Array(1,Array(0=>;xx;xxx;xxxs))" not array of array
)

MY GOAl是为了获得一系列数组这样的东西:

Array
  (
  0 => Array(0,Array(0=>";sdfds")),//array of array
  1 => Array(0,Array(1=>";sa;d")),//array of array
  2 => Array(1,Array(0=>";xx;xxx;xxxs"))//array of array
  );

I.please如何帮助? ?>

1 个答案:

答案 0 :(得分:1)

假设HTML,

echo nl2br(print_r($x, true));

$ x =你的变量。

这将在每个级别中添加换行符。您可能还希望这样做以保留空格:

echo str_replace(" ", " ", nl2br(print_r($x, true)));