简体   繁体   English

如何在没有表格的页面之间传递 arrays php

[英]How do you pass arrays between pages without a form in php

I have used multi-dimesional array from a database to bring back a row ($dataTotal) and another one to bring back a position in that row ($data['position1']) depending on if I want to display anything in the array on that first page我已经使用数据库中的多维数组来带回一行($dataTotal)和另一个在该行($data['position1'])中带回 position,具体取决于我是否要显示数组中的任何内容在第一页

When the user clicks on a link, I would like the page to override the existing value of the $data array, and pass that new value to a new page where I can display different positions of that same array.当用户单击链接时,我希望该页面覆盖 $data 数组的现有值,并将该新值传递给一个新页面,我可以在其中显示同一数组的不同位置。 For eg $data['position2'].例如 $data['position2']。

Page 1第 1 页

 <a href="../webapp/pages/influencer/person.php?data=<?php $data =  $dataTotal[0]; echo $data; ?>"

Page 2第2页

$data = $_GET['data']; echo $data['position2'];

My only problem is that it shows that Im passing a string with this link.我唯一的问题是它表明我通过这个链接传递了一个字符串。 So incompatible datatypes.所以不兼容的数据类型。

for this purpose you can use serialize() function to convert a array to a string and then encode it with urlencode() .为此,您可以使用serialize() function 将数组转换为字符串,然后使用urlencode()对其进行编码。 example:例子:

<a href="../webapp/pages/influencer/person.php?data=<?php $data =  $dataTotal[0]; echo urlencode(serialize($data)); ?>";

$data = unserialize(urldecode($_GET['data'])); 

echo $data['position2'];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM