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…
I’m clueless in this part… is this javascript? if so, you need to use a JSON Parser like the JSON2.js https://github.com/douglascrockford/JSON-js
this file creates a Javascript JSON Object which allows you to parse a JSON string to a Javascript object. (you can always use eval() but it won’t prevent against possible malicious code…) or the other way around… from a Javascript Object transform into a JSON string.
After converting to a JSON string you just need to send the data through AJAX to a PHP file, like:
(I’m using jQuery to save some lines…)
Then on the php_file.php you would have something like this: