So I am currently working on a bunch of curl statements in PHP with a sql table to modify or create new keys, based on the $flag
. This will be of set size 2 without change (or atleast for now).
What I am wondering is if Flag1 exists in this url, I would want to use a PUT, but Flag2 does not exist, I would need a POST. How would I be able to modify this code to determine PUT vs POST.
The loop logic has not been implemented yet. For now I am just trying to put $flag[0] in with $new_Val[0] and trying to modify PUT vs POST but I dont know how.
$flag = array("Flag1", "Flag2");
$new_Val = array("Val1", "Val2");
$url = "myurl/thing/$flag/id/1112";
$my_data = array( "Key" => "$flag[0]", "Value" => "$new_Val[0]");
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($my_data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( stuff in here)
result = curl_exec($ch);
$json = json_decode($result);