PHP SOAP request with multiple same keys



I am trying to create an XML structure as shown below



<GetResultList>
<GetResultListRequest>
<Filters>
<Filter>
<Name0>string0</Name>
<Value0>string0</Value>
</Filter>
<Filter>
<Name1>string1</Name>
<Value1>string1</Value>
</Filter>
</Filters>
</GetResultListRequest>
</GetResultList>


To form the XML i'm using the following PHP code



$param = array();
for($i=0;$i<2;$i++)
{
$param[] = array('filter' => array('Name'.$i=>'string'.$i, 'Value'.$i=>'string'.$i));
}


To my surprise only the last iteration of the loop is formed as an XML structure in the getLastRequest()


XML formed is



<GetResultList>
<GetResultListRequest>
<Filters>
<ns1:Filter>
<Name>string</Name>
<Value>string</Value>
</Filter>
</GetResultListRequest>
</GetResultList>


I am ignoring teh GetResultList, GetResultListRequest and Filters element in the code above.


My question is why is only the last iteration of the loop accepted? What is the workaround to achieve the required XML output ?


No comments:

Post a Comment