开发者

convert string (array...) to an array php?

开发者 https://www.devze.com 2023-01-30 18:04 出处:网络
echo $_POST[\'var\']; Array(0,Array(0=&g开发者_Go百科t;;sdfds)),Array(0,Array(1=>;sa;d)),Array(1,Array(0=>;xx;xxx;xxxs))
echo $_POST['var'];

Array(0,Array(0=&g开发者_Go百科t;;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);

OUPTUT

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 is to get an array of array some thing like this:

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
  );

How Can I.please help ? ?>


Assuming HTML,

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

$x = your variable.

This will put newlines in each level. You might also want to do this to preserve spaces:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号