将php多维数组存储在localstorage中


store php multidimensional array in localstorage

我正在构建一个网站,用户可以在其中使用该网站并输入数据。然而,为了保存他们的数据,他们需要登录到我的网站(使用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上,以便在他们使用facebookconnect登录后,我可以使用这些数据?这是最好的方式吗?还是我应该做其他事情?

<?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。