Like ALL said, you need to echo each individual statement. You als need to ensure that the Javascript code is inside script tags.
PHP Code:
?>
<script type="text/javascript">
<!--
    var myarray = Array(<?php echo(count($myarray)) ?>);

    <?php for($x 0$x count($myarray); $x++): ?>
        myarray[<?php echo($x?>] = <?php echo(htmlspecialchars($myarray[$x])) ?>;
    <?php endfor; ?>
//-->
</script>