Home  >  Article  >  Backend Development  >  可不可以把print_r输出还原为数组

可不可以把print_r输出还原为数组

WBOY
WBOYOriginal
2016-06-06 20:10:281128browse

我想通过HTTP GET传递一个数组,那么我使用print_r输出了一个数组,假设输出结果是

Array
(

<code>   [0] => aaaa      
   [1] => bbbb      </code>

)

那么我在接收之后如何转换转换成数组?

回复内容:

我想通过HTTP GET传递一个数组,那么我使用print_r输出了一个数组,假设输出结果是

Array
(

<code>   [0] => aaaa      
   [1] => bbbb      </code>

)

那么我在接收之后如何转换转换成数组?

方便的话使用json_encodeserialize 或者var_export来产生被传递的内容吧,这几个方法都有现成的反解函数,而print_r没有。

输出之前就是数组啊,为什么还要输出后再转换?输出后就是已经到html端了,此时php处理已经完成,再转成数组没有意义啊,我觉得是不是你的整体理解有问题?不知道下面的代码能不能帮到你

<code>//file: test.php
<?php echo json_encode($_GET['array']); //使用json格式输出
echo $_GET['array'][0]; //正常输出 array 数组的第一个元素
print_r($_GET['array']); //print_r方式
?>
</code>

你可以这样访问它 http://localhost/test.php?array[]=hi&array[]=Cansll

楼主,你都已经打印数组了为什么还需要将打印的文本转换成数组呢?不太明白你的需求啊.

本身就是數組了 為什麼還要轉成數組?是格式問題麼?

你这个问题就矛盾啊,想了解一下你的需求

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn