0

from the below Code 2 references Code 2 via $sendData. I would like to completely remove Code 1, and only using Code 2. Can I please get help writing code 1 into code 2, perhaps in form of array

CODE 1

$sendData = '{ "messages" : [ { "content" :  "Hello", "destination" : "0718860000" } ] }';

CODE 2

$options = array(
    'http' => array(
        'header'  => array("Content-Type: application/json", $authHeader),
        'method'  => 'POST',
        'content' => $sendData,
    )
);

1 Answer 1

1
$options = [
    'http' => [
        'header'  => [ "Content-Type: application/json", $authHeader ],
        'method'  => 'POST',
        'content' => json_encode([
            "messages" => [
                [ 
                    "content" => "Hello",
                    "destination" => "0718860000",
                ],
            ],
        ]),
    ),
);
Sign up to request clarification or add additional context in comments.

1 Comment

Hello and welcome to StackOverflow @BrightMtabela! Please mark the answer as "accepted" left to the answer if you are satisfied, this helps other users to quickly find the best answer to your question in the future.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.