var MyArray = <?= json_encode( $MyArray ) ?>;
HTML input elements cannot hold more than one value. If you do need to encode an array into a form for some reason you'll have to create an input element for each value as follows.
<?php foreach ( $array as $key => $value ): ?>
<input type="hidden" name="myarray[<?= $key ?>]" value="<?= $value ?>" >
<?php endforeach ?>