2
I have this class where I can 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 the var_dump($data)
It returns me 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"]
, but the examples do not contain the structure with 2 objects stdClass
and an array return
.
Someone can help me?
EDIT
I added the code below to the original and was able to visualize the plates. There is a way less paleactive than this?
$xml = json_decode(json_encode($data),true);
echo $xml["return"][0]["placa"];
echo $xml["return"][1]["placa"];
try this: foreach($data->Return as $veiculo){ echo $veiculo->placa; }
– Derlei Lisboa
@Derleilisboa. It worked perfectly!
– thiagofred
then I draw up a complete response and put as a response, to follow the pattern of the site that does not recommend responses in the comments.
– Derlei Lisboa
It took a little longer to publish the answer ;)
– Derlei Lisboa