Type conversion between PHP client and Java webservice
Posted
by a1ex07
on Stack Overflow
See other posts from Stack Overflow
or by a1ex07
Published on 2010-05-14T22:50:23Z
Indexed on
2010/05/14
22:54 UTC
Read the original article
Hit count: 327
I have a web service implemented as EJB. One of it's methods returns Map<String,String>
. On client side I use php :
$client = new SoapClient($wsdl,array("cache_wsdl"=>WSDL_CACHE_NONE));
$result = $client->foo($params);
Everything works fine, but I would like $result->return to be an associative array. Now it looks like
array(10) { [0]=> object(stdClass)#46 (2) { ["key"]=> string(4) "key1"
["value"]=> string(4) "val1" } ....
I want
array(10) {"key1"=>"value1", "key2"=>"value2", .... }
The obvious solution is to iterate through this array and create a new array
$arr = array();
foreach ($result->return as $val)
$arr[$val->key] = $val->value;
But I wonder if there is a better way to get an assosicative array ?
Thanks in advance.
© Stack Overflow or respective owner