Php curl is written in the same function, but it is requested at the same time.

I write curl on a function like this:

function httpRequest ($api, $data_string)
{
  $ch = curl_init($api);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
  $result = curl_exec($ch);
  curl_close($ch);

  return json_decode($result);
}

and then I ask for it with someone else

.
$api_a = "a";
$api_b = "b";

$get_a = array(
      "session" => $_SESSION["session"]
    );
    $get_a_str = json_encode($get_a);
    $get_a = httpRequest($api_a, $get_a_str);
    
$get_b = array(
      "session" => $_SESSION["session"]
    );
    $get_b_str = json_encode($get_b);
    $get_b = httpRequest($api_b, $get_b_str);

write on the same website:

  <?foreach ($get_a->dataA as $key) {?>
          <?=@$key->{"name"};?>
        <?}?>
  <?foreach ($get_b->dataB as $key) {?>
          <?=@$key->{"name"};?>
        <?}?>

Why not at the same time?
he can only ask for one of them, and the other will be invalid? (only when you are at the top)

he will hug:

Undefined variable: get_b
Trying to get property "dataB" of non-object
Invalid argument supplied for foreach()

I just need to drop An and I can do it. B
I can change A by dropping B

.
Mar.01,2021
Menu