Marios Marios - 1 year ago 99
PHP Question

How to get a field from a class over a soap call in php

I have a web service running in visual studio 2015 with a method in it called GetTables(). In php now, i'm trying to get the response from the above method call. Here is my code in Php:


$wsdl_url = 'http://localhost:1336/DisplayInfoWebService.svc?wsdl';
$client = new SOAPClient($wsdl_url);

$res = $client->GetTables();

echo '<pre>';
echo '</pre>';

The Above Php returns the following:

stdClass Object
[GetTablesResult] => stdClass Object
[tablename] => Array
[0] => stdClass Object
[name] => alcopops

[1] => stdClass Object
[name] => beers

[2] => stdClass Object
[name] => ciders

What i'm trying to do is get those values (alcopops,beers,ciders) and parse them into a php array so i can use them later. How can i do it?

Answer Source

Do you mean $res->GetTablesResult->tablename or $res->GetTablesResult->tablename[0]->name? Or perhaps even something like:

$builtArray = [];
foreach($res->GetTablesResult->tablename as $table) {
  $builtArray[] = $table->name;

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download