0

I have this array that returns a parameter error. Why?

        echo json_encode(
        array("replies" => array(
        array("message" => "Success ✅")
        )),
        array("variables" => array(
        array("data1" => "data2")
        ))          
        );
Club
  • 111
  • 1
  • 8
  • Wrap the whole parameter in an array: `echo json_encode(array(...));`. You're actually providing 2 parameters to `json_encode`. Error: `Argument #2 ($flags) must be of type int, array given`. – bloodyKnuckles May 31 '22 at 14:36

1 Answers1

0

You need to wrap the array in a single variable because json_encode second argument is the flag and you have passed the array so it's a return error. For more info see this link https://www.php.net/manual/en/function.json-encode.php or try with below example

echo json_encode(
    [["replies" => ["message" => "Success"]],
    ["variables" => ["data1" => "data2"]]]);

#json #arraytojson #php