How exactly do you use json_decode to pass a javascript array to php?

Posted by Adam on Stack Overflow See other posts from Stack Overflow or by Adam
Published on 2010-12-28T04:31:51Z Indexed on 2010/12/28 4:53 UTC
Read the original article Hit count: 162

Filed under:
|

This is how I got my php array to javascript

echo 'var daysofweek = '.json_encode($daysofweek).';';

Now I am aware that json_decode can do the opposite, however the problem is I don't know the syntax to do so.

I tried:

<script>
var array_days = new Array();

array_days[] = "psdfo";
array_days[] = "bsdf";

<?php
$array_days = json_decode(?>array_days<?php);?>

</script>

yes im clueless.

I forgot to mention that I want to send an array through post, having all my information regarding all the form values dynamically created by javascript. Otherwise, I wouldn't know which name="" to look for as it will be decided by the user. Unless someone else has an alternative solution...

© Stack Overflow or respective owner

Related posts about php

Related posts about JavaScript