Hello. There was a small problem with the adoption of POST data when transferring them to a PHP script via the ajax method.

The bottom line is that I want to receive all the data from the json data table, which is transmitted through the script. There are a lot of variables, so typing each into a php file is not an option like this:

$variable = $_POST["variable"]; 

The construction above works and the script does everything properly. I decided to use the foreach loop to process the $ _POST data array, but for some reason it does not accept data:

 foreach ($_POST as $key => $val) { $key = $val; } 

Could you tell me how best to accomplish the task and why the foreach in this case does not accept the data?

  • uhh .. what do you expect from $key = $val ? remove it. In terms of your above, $_POST['varibale'] when iterating with foraech $key will take the value of the key string 'variable' , and $val will become $_POST['variable'] . - teran
  • for clarity, replace this with your $key=$val with print_r([$key, $val]) - teran
  • Thank you, blunted a little in this moment - SlyFox

1 answer 1

Thanks terran'u for help. With the following construction, everything worked.

 foreeach($_POST as $key => $val) { } extract($_POST);