let jsVariable = <?= $phpVariable ?>;
fetch('/some/url', {
method: 'POST',
headers: {
'Content-Type': 'application/json;charset=utf-8'
},
body: JSON.stringify({some: 'object'})
}).then(res => res.json()).then(json => {
console.log(json);
})
function flattenArray($array, &$resultArray = [], $name = '')
{
foreach($array as $key => $value) {
if (is_array($value)) {
flattenArray($value, $resultArray, $name ? $name."[$key]" : $key);
} else {
$resultArray[$name ? $name."[$key]" : $key] = $value;
}
}
return $resultArray;
}