Return to Snippet

Revision: 51798
at October 4, 2011 21:56 by dato


Initial Code
<?php
$arreglo = array(
'clave 1' => 'valor 1',
'clave 2' => 'valor 2',
'clave x' => 'valor x',
);
?>

<script language="javascript">
var arr = {

<?php
foreach($arreglo as $key => $values){
$arr .= "'" . $key . "'" .   " : " . "'" . $values . "'" . ",";
}
$arr =  substr_replace($arr, '', -1);
echo $arr;
?>

};
</script>

Initial URL

                                

Initial Description

                                

Initial Title
Convert PHP array into Javascript Array

Initial Tags
javascript, php, array

Initial Language
JavaScript