繁体   English   中英

将PHP多维数组存储在localstorage中

[英]store php multidimensional array in localstorage

我正在建立一个网站,用户可以在其中使用该网站并输入数据。 但是,要保存他们的数据,他们需要登录到我的网站(使用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登录后就可以使用该数据? 这是最好的解决方法还是我应该做其他事情?

<?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序列化的数组。

暂无
暂无

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

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