I want to convert a multi-dimensional PHP array to JavaScript and found this script in a post here;
<script type='text/javascript'>
<?php
$js_array = json_encode($php_array);
echo "var javascript_array = ". $js_array . ";\n";
?>
</script>
But the JS array remains empty. Is it because I have a multi-dimensional array?
var_dump
of your$php_array
. – deceze Aug 1 '11 at 7:02$php_array
isn't empty. If its not, then$js_array
will not be either. :) – daGrevis Aug 1 '11 at 7:07json_encode()
is available from 5.2 onward. Do you have error reporting on? – Juhana Aug 1 '11 at 7:20