how can I create a function that can post my parameters using curl
===

I developed a API for my website. API working 100% correctly. But I designed it to catch and execute functions from this kind of POST parameters`$_POST['functionName'];` `$_POST['parameter'];` Now, in request page i want to send those as `$_POST`, I managed to do deal with that. But my problem is, **how can I create a function that can post my parameters** for each functions in API using `curl`. Here is my code which send requests to my **API**.

    $url = 'http://localhost/myapi/api.php';
    $postfields['functionName'] = "myFunction";
    $postfields['parameter'] = "1";
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 100);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
    $data = curl_exec($ch);
    $results = json_decode($data, true);
    curl_close($ch);