<?php echo $variable1 ?> <?php echo $variable2 ?> <?php echo $variable3 ?> ... <?php echo $variablen ?>
I know I can store some variables in cookies, and access these values via cookies, but values in cookies are relatively stable values. Moreover, there is a limit, you can not store many values in cookies, and the method is not that convenient. Is there a better way to do it?
Using cookies for this is a very unsafe and unreliable way, as they are stored clientside and therefore open for any manipulation or won't even get accepted/saved. Don't use them for this type of interaction. jQuery.ajax is a good start IMHO.
If AJAX isn't an option you can use nested data structures to simplify.
<?php $var = array( 'qwe' => 'asd', 'asd' => array( 1 => 2, 3 => 4, ), 'zxc' => 0, ); ?> <script>var data = <?php echo json_encode($var); ?>;</script>