Usually we use json(as it is a better option than php's serialization) to transfer a php array into JS to access it from there, or we can use cookie.
But can't we do the same thing without those? For example lets take a look at the first code.

```
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <?php
     $elements = array('myname', 'myage');
    ?>

    <script type="text/javascript">

    var elements = <?php echo json_encode($elements) ; ?> ;

  //use the elements array afterwards

    </script>

</body>
</html>

```

But we can access that php array without using json, like this way also

```
   <script type="text/javascript">

    var elements = [];
      <?php foreach($elements as $element) : ?> 

      elements.push("<?php echo $element; ?>");

      <?php endforeach; ?>

 //use the elements array afterwards

    </script>

```

So other than secutity reason why do we need json here?