简体   繁体   中英

nest array return from php web service using nusoap lib

I want to return nested array from web service in php upto i have do like this way

$ordArr = array("orderid"=>$orderId,"orderdate"=>$orderdate,"ordertype"=>$ordertype);

$userArr = array("userid"=>$userId,"name"=>$name,"address"=>$address);

i am able to define complex type for single array and return single array using this way

$server->wsdl->addComplexType(
 'User',
 'complexType',
 'struct',
 'all',
 '',
      array(
       'userId' => array('name' => 'userId',
           'type' => 'xsd:int'),
       'name' => array('name' => 'name',
           'type' => 'xsd:string'),
       'address' => array('name' => 'address',
           'type' => 'xsd:string')
      )
);

but how to define complext type for the nested array like

$userArr = array("userid"=>$userId,"name"=>$name,"address"=>$address,"order"=>$ordArr);

i little bit confused into the type define in complex type for array

like for string set type as 'xsd:string' but for the array type=?

for the nested array used into the addcomplextype using nusoap lib to create the web service in php.

$ordArr = array("orderid"=>$orderId,"orderdate"=>$orderdate,"ordertype"=>$ordertype);

$userArr = array("userid"=>$userId,"name"=>$name,"address"=>$address);

define first complex type for nested array which you want to add into the main array or outer array.

$server->wsdl->addComplexType(
 'Order',
 'complexType',
 'struct',
 'all',
 '',
      array(
       'orderid' => array('name' => 'orderid',
           'type' => 'xsd:int'),
       'orderdate' => array('name' => 'orderdate',
           'type' => 'xsd:string'),
       'ordertype' => array('name' => 'ordertype',
           'type' => 'xsd:string'),
      )
);

now add this complex type into the main array complex type into the array to define the array type. When you create the complex type as struct/array that type was used to define that object type into the array

now define the user complex type for

$userArr = array("userid"=>$userId,"name"=>$name,"address"=>$address,"order"=>$ordArr);

$server->wsdl->addComplexType(
 'User',
 'complexType',
 'struct',
 'all',
 '',
      array(
       'userId' => array('name' => 'userId',
           'type' => 'xsd:int'),
       'name' => array('name' => 'name',
           'type' => 'xsd:string'),
       'address' => array('name' => 'address',
           'type' => 'xsd:string'),
       'order' => array('name' => 'order',
           'type' => 'tns:Order'),
      )
);

need more details see this tutorial

tutorial for nested array

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM