I am New to this. I want to create text file in PHP for that I need two array for Clint side. Problem is that I have passed the array from JavaScript to PHP but In PHP it does convert into single string of array of javascript.
test.html
<form method="post" id="theform" action="example.php">
<!-- your existing form fields -->
<input type="hidden" id="markers" name="markers">
<button>Submit</button>
</form>
<script>
window.onload = function () {
var form = document.getElementById('theform');
form.addEventListener('submit', function () {
var markersField = document.getElementById('markers');
var markers = [1, 2, 3];
markersField.value = JSON.stringify(markers);
});
}
</script>
example.php
<?php
$array=json_decode($_POST['markers']);
foreach($array as $value){
print $value;
}
?>
output of example.php
123
Expected Output
$array[0] = 1;
$array[1] = 2;
$array[2] = 3;