I'm using nusoap to connect to a soap webservice. The xml that the class sends to the service is constructed from an array, ie:
$params = array("param1" => "value1", "param2" => "value1");
$client->call('HelloWorld', $params, 'namespace', 'SOAPAction');
This works fine. A multidimensional array also constructs a nice nested xml message.
I encounter a problem when i need two tags with the same name:
<items>
<item>value 1</item>
<item>value 2</item>
</item>
$params = array("items" => array("item" => "value 1", "item" => "value 2"));
The second item in the array overwrites the first which results in:
<items>
<item>value 2</item>
</item>
How can achieve this?
The problem is with the inner array()
$test_array = array("item" => "value 1", "item" => "value 2");
creates an array with a single key ("item").
Try this and see if it works:
$params = array("items" => array("item" => array("value 1", "value 2")));
No guarantees, though... I haven't used nusoap in a long time and don't have PHP installed here to test it.
Your core problem is you're writing invalid PHP code
$x = array("items" => array("item" => "value 1", "item" => "value 2"));
var_dump($x);
array(1) {
["items"]=>
array(1) {
["item"]=>
string(7) "value 2"
}
}
Which of course wont work, as its synonymous with
$x = array();
$x['items'] = array();
$x['items']['item']='value 1';
$x['items']['item']='value 2';
which of course won't work.
Your best bets are with
array("items"=>array( "value1","value2") );
and hoping the numeric keys will "work" or
array("items"=>array("item"=>array("value1","value2")))
in the event it is so inclined.
$params = '<person xsi:type="tns:Person"><firstname xsi:type="xsd:string">Willi</firstname><age xsi:type="xsd:int">22</age><gender xsi:type="xsd:string">male</gender></person>';
$result = $client->call('hello', $params);
http://nusoap.cvs.sourceforge.net/viewvc/checkout/nusoap/samples/wsdlclient3b.php
This one shows using an un-keyed ( ie: numeric ) array as an input source: http://nusoap.cvs.sourceforge.net/viewvc/checkout/nusoap/samples/wsdlclient4.php
This is strange because, method:
$params = array('items' => array('item' => array('value1', 'value2')))
$client->call( 'action', $params );
works form me. As explained in this link
Maybe you need newer version of nusoap?
we have solved this problem by passing string instead of array to nusoap call function. please check link below http://fundaa.com/php/solved-duplicate-tags-in-nusoap/