2015-08-19 66 views
1

我正在使用亚马逊API PHP库从我们的卖家中心帐户下载报告。PHP亚马逊API多功能变量

有一个名为“UpdateReportAcknowledgements”的API调用,它使用库中的MarketplaceWebService_Model_UpdateReportAcknowledgementsRequest。该类有一个setReportIdList方法,它以MarketplaceWebService_Model_IdList作为参数。 MarketplaceWebService_Model_IdList类有一个名为withId的方法,这是我需要帮助的地方。

withId方法库中的这些注释:

/** 
* Sets single or multiple values of Id list via variable number of arguments. 
* For example, to set the list with two elements, simply pass two values as arguments to this function 
* <code>withId($id1, $id2)</code> 
*/ 

因此可以接受多个ID变量(然后使用func_get_args()函数内)。我确定接受一个数组会更容易(对我而言),但我并不想更新Amazons库代码。

我有一个array()包含3个ID(存储为字符串)。

如何取我的数组,并将其变为withId方法的3个参数变量..?

UPDATE 我的数组目前有3个ID,但可能会更改为1或6或15或任何其他数字。每次调用方法时,ID的数量都会改变。

+0

我不知道我正确理解你的问题。你不能这样做:'withId($ array [0],$ array [1],$ array [2])'? –

+0

对不起,这次我在我的阵列中有3个ID,但下次可能是1或8或15。 –

回答

1

我目前无法测试,但我认为,您可以使用call_user_func_array,请参阅此documentation

所以你的情况,这将是:

call_user_func_array(array($instanceToCallOn, 'withId'), $myArray); 

也有使用reflection因为PHP 5.1的可能性:

$myReflection = new ReflectionMethod('MarketplaceWebService_Model_IdList', 'withId'); 
$myReflection->invokeArgs($instanceToCallOn, $myArray); 
+0

我用'call_user_func_array()',似乎很好地工作......谢谢! –