将变量传递给数组PHP中的值

I'm trying to create a variable and place it in an array. Like this:

    $ch = curl_init('https://apps.net-results.com/api/v2/rpc/server.php?Controller=Contact');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERPWD, 'user:pass');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,
    json_encode(
        array(
            'id' => uniqid(),
            'method' => 'getMultiple',
            'jsonrpc' => '2.0',
            'params' => array(
                'offset' => 0,
                'limit' => 50, // 10, 25, or 50
                'order_by' => 'contact_email_address', //'contact_email_address' or 'contact_id'
                'order_dir' => 'ASC', //'ASC' or 'DESC'
            )
        )
    )
);

$strResponse = curl_exec($ch);
$strCurlError = curl_error($ch);
if (!empty($strCurlError)) {
    //handle curl error
    echo "Curl Error<br />$strCurlError<br />";
} else {
    //check for bad user/pass
    if ($strResponse == "HTTP/1.0 401 Unauthorized: Your username name and/or password are invalid.") {
        //handle login error
        echo "Error<br />$strResponse<br />";
    } else {
        //successful call, check for api success or error
        $objResponse = json_decode($strResponse);
        if (property_exists($objResponse, 'error') && !is_null($objResponse->error)) {
            //handle error
            $intErrorCode = $objResponse->error->code;
            $strMessage = $objResponse->error->message;
            $strData = $objResponse->error->data;
            echo "Error<br />Code: $intErrorCode<br />Message: $strMessage<br />Data: $strData<br />";
        } else {
            //handle success
            //echo "Success<br />";
            $objResult = $objResponse->result;
            $intTotalRecords = $objResult->totalRecords;
            //echo "Total Records: $intTotalRecords<br />";
            $arrContacts = $objResult->results;
            //echo $arrContacts[0]->country;
            //echo $arrContacts[3]->last_name;
            //echo "<pre>";
            //print_r($arrContacts);
            //echo "<pre/>";

        }
    }
}

I'm not sure this is possible. I have tried doing different things such as creating a class, and placing the function in the class in the array, but it doesn't work. Can anyone give me the correct syntax of what I should try?

If you pass params via post you should use http_build_query() and you can pass it as CURL post fields.

You should set:

$array = [
    'id'      => uniqid(),
    'method'  => 'getContactActivity',
    'jsonrpc' => '2.0'
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://example.site");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($array));
curl_exec($ch);
curl_close($ch);

Leave out the call to json_encode(). The value of the CURLOPT_POSTFIELDS option should be either an associative array or a string in URL-encoded format. If you use an array, it will automatically encode it for you.