gpt4 book ai didi

php - 将php多维数组存储在本地存储中

转载 作者:行者123 更新时间:2023-11-28 08:55:31 24 4
gpt4 key购买 nike

我正在构建一个网站,用户可以使用该网站并输入数据。然而,为了保存他们的数据,他们需要登录我的网站(使用 facebook connect)。他们输入的数据存储在一个 php 多维数组中,其结构如下:

$order = array();
$order[] = array('rank'=>'1', 'day'=>'Tues'); // This $order[] has input inputted several times by the user
// I haven't included all the code because it's big, all that's really needed is to see the structure of $order

我的问题是,如何将 php 多维数组转换为 javascript,然后如何使用 localStorage.setItem() 将其存储到 localStorage 上,以便他们使用 facebook connect 登录后我可以使用该数据?这是解决问题的最佳方法还是我应该做其他事情?

<?php
require_once 'src/facebook.php';
$order = array();
$order[] = array('rank'=>$column, 'day'=>$day);
$loginUrl = $facebook->getLoginUrl(array('scope'=>'user_about_me,email'));
?>

<html>

<head>
<script type="text/javascript">
function fblogin() {

var fk = "<?php echo $loginUrl; ?>";
// What do I do here to convert $order into javascript?
// What do I do here to store converted $order onto localStorage()
window.location = "<?php echo $loginUrl; ?>";
}
</script>
</head>

<body>
<INPUT type="image" src="img/fb.png" onclick="fblogin()" />
</body>

</html>

最佳答案

json_encode() 您的数组,将其发送到客户端,并 localeStorage 序列化数组。

关于php - 将php多维数组存储在本地存储中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18554228/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com