PHP的数组值传入JavaScript的数组里

时间:2022-04-06 06:43:14

<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
       <title>PHP的数组值传入JavaScript的数组里</title>
       <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="JavaScript">
var arr=new Array(4);
    arr[0] = "George"
    arr[1] = "John"
    arr[2] = "Thomas"
    arr[3] = "James"
var i=9;
</script>

<?php
   $array=array("88","99","66","你好");
   echo"<script>Array=$array</script>";
?>

<script language="JavaScript">
var arr = <?php echo json_encode($array)?>;
alert(arr[3]);
</script>

</head>
<body>
 网页页面!
</body>
</html>