简体   繁体   中英

Php - How do I use a for loop inside API request

Here is a sample request which works, but the names are hard coded

$client->batchDeleteAttributes(array(
    'DomainName' => $domainName,
    'Items' => array(
         array('Name' => '5149572a86deb5161fbb22bdab',),
         array('Name' => '5149572a86deb5161fbf7487b9',),
     )
));

I can get the name values using the following loop

foreach($_POST['d'] as $key => $value)
{

}

I am confused how to integrate the foreach loop with the api request. I assume I need to create an array using the foreach loop and then use that array in the api request but I don't know the syntax.

Thanks!

Without knowing the format of your $_POST data it's hard to give a detailed solution, but something along these lines should get you heading in the right direction:

$names = array();
foreach ($_POST['d'] as $value)
{
    $names[] = array('Name' => $value);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM