0

寻找有关多维数组的一些建议,将变量推送到 foreach 循环内的 POST 调用中。

我目前有一个包含 IF 子句的 foreach 循环:

foreach ($responseData['data'] as $key => $value) {
  if (strtotime($value['attributes']['created_time']) > $currentDateMinusThirtyMinutes) {
  array_push($emails, $value['attributes']['email']);
  }
}

这应该为所有满足在最近 30 分钟内创建的条件的数组获取电子邮件。

但是,现在我被卡住了,我需要获取多个其他变量并调用类似于下面的 POST 调用:

https://developer.example.co.za/{$PAGE}/create?reference={$ID}&currency=ZAR&amount={$AMOUNT}&firstname={$FIRST}&lastname={$LAST}&email={$EMAIL}&sendmail=true

我需要知道的是,有没有更好的方法来处理 foreach 循环?

foreach 是正确的方法吗?

本质上,我需要遍历每个$responseData['data']返回并对上述 URL 进行 POST 调用。

任何建议将不胜感激。

4

1 回答 1

0

通过创建一个存储我需要的值的 Data_array 来解决这个问题,然后在 foreach 循环中添加 POST 调用,然后就可以了。

foreach 最终看起来像这样:

foreach ($responseData['data'] as $key => $value) {
  if (strtotime($value['attributes']['created_time']) > $currentDateMinusThirtyMinutes) {
    $data_array[] = array(
     "id" => $value['attributes']['id'],
     ***add rest of vars you want***
    );
  ***Add POST call or whatever else you want to do***
  }
}

感谢@darklightcode 向我指出仅拆分我想要的变量的想法。

于 2020-02-10T11:08:52.460 回答