-1

I'm curently looking to consume on a php server a JSON object sent on a POST request. The Request Payload looks like:

'{"0":["item1",12,"23"],
"1":["item2",5,"34"],
"2":["item3",6,"4"],
"3":["item4",34,"6"],
"4":["item5",7,"4"]}'

However, I don't have any clue of how the $_POST variable would look like. I've already tried getting any value with i.e.

$_POST['0'][0];
$_POST[0][0];
(array) $_POST[0];

I've also tried with stating content-type: application/json and also without it. The main question is how the $_POST variable looks like when being a 2D array, since I can easily consume a json like: {"0":"a", "1":"s", "2":"d"}'.

1 Answers1

-1

To consume the raw payload in PHP (not a form or something else), you need to read the php://input stream:

<?php

$payload = file_get_contents('php://input');
$data = json_decode($payload);

// now you can use your $data
Robo Robok
  • 21,132
  • 17
  • 68
  • 126