在我的PHP腳本中,我有一個多維和關聯數組,我想將其「轉換」爲一個javascript數組。該陣列看起來像這樣在PHP:如何在JavaScript中創建多維和關聯數組?
<?php
$myArray = array(
array("value" => 1, "label" => "First"),
array("value" => 2, "label" => "Second")
)
?>
,現在我想創建一個數組在javascript等效的陣列,通過一個foreach循環。事情是這樣的:
<script>
var myArrayInJS = new Array();
<? foreach($myArray as $innerArray): ?>
// What do I write here?
<? endforeach; ?>
</script>
可能重複http://stackoverflow.com/questions/4329092/multi-dimensional-associative-arrays-in-javascript – 2012-03-02 15:44:27