在localstorage中存储php多维数组

时间:2013-09-01 00:55:29

标签: php javascript local-storage

我正在建立一个用户可以使用该网站并输入数据的网站。但是为了保存他们的数据,他们需要登录我的网站(使用facebook连接)。他们输入的数据存储在具有以下结构的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>

1 个答案:

答案 0 :(得分:0)

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