I have a web service implemented as EJB. One of its 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.