I have this class where I can do the query and return data from an external webservice:
$params = array(
'usuario' => $usuario,
'senha' => $senha,
'quantidade' => 2
);
$wsdl = 'http://xxxx.com?WSDL';
$options = array(
'uri'=>'http://schemas.xmlsoap.org/soap/envelope/',
'style'=>SOAP_RPC,
'use'=>SOAP_ENCODED,
'soap_version'=>SOAP_1_1,
'cache_wsdl'=>WSDL_CACHE_NONE,
'connection_timeout'=>15,
'trace'=>true,
'encoding'=>'UTF-8',
'exceptions'=>true,
);
try {
$soap = new SoapClient($wsdl, $options);
$data = $soap->obterDados($params);
}
catch(Exception $e) {
die($e->getMessage());
}
echo "<pre>";
var_dump($data);
echo "</pre>";
But the result that var_dump($data)
returns me is something like this:
object(stdClass)#2 (1) {
["return"]=>
array(2) {
[0]=>
object(stdClass)#3 (26) {
["idVeiculo"]=>
int(123456)
["placa"]=>
string(9) "ABC2222-2"
}
[1]=>
object(stdClass)#4 (26) {
["idVeiculo"]=>
int(123457)
["placa"]=>
string(9) "ABC1111-2"
}
}
}
I need to get the data ["idVeiculo"]
and ["placa"]
, however the cases exemplified do not contain the structure with 2 stdClass
objects and a return
array.
Can anyone help me?
EDIT
I added the code below the original and I was able to see the plates. Is there a less palatable form than this?
$xml = json_decode(json_encode($data),true);
echo $xml["return"][0]["placa"];
echo $xml["return"][1]["placa"];