I have an API that takes parameters from a post through JSON and I want to extract one of the values in an array for a key value pair. However, despite many attempts, I can't get it to work.
Here is my code:
$json = file_get_contents('php://input'); $request = json_decode($json, true); $parameters = $request["result"]["parameters"]; When I log $parameters to a text file, it log as
{"numberofhits":"5"} However, my efforts to capture the value 5 are not working:
$numhits = $json['numberofhits']; logs as empty. So does:
$numhits = $parameters->numberofhits; How can I capture the value 5 in a variable?