使用nussoaplib从PHP web服务返回的嵌套数组


nest array return from php web service using nusoap lib

我想从php的web服务中返回嵌套数组,直到我这样做

$ordArr = array("orderid"=>$orderId,"orderdate"=>$orderdate,"ordertype"=>$ordertype);
$userArr = array("userid"=>$userId,"name"=>$name,"address"=>$address);

我可以为单个数组定义复杂类型,并使用这种方式返回单个数组

$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')
      )
);
但如何为嵌套数组定义复杂类型,如
$userArr = array("userid"=>$userId,"name"=>$name,"address"=>$address,"order"=>$ordArr);

我对数组

的复杂类型定义有点困惑

如字符串设置类型为'xsd:string',但对于数组类型=?

为使用nussoap库在php中创建web服务的addcomplextype中使用的嵌套数组。

$ordArr = array("orderid"=>$orderId,"orderdate"=>$orderdate,"ordertype"=>$ordertype);
$userArr = array("userid"=>$userId,"name"=>$name,"address"=>$address);

为要添加到主数组或外部数组中的嵌套数组定义第一个复杂类型。

$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'),
      )
);

现在将这个复杂类型添加到主数组的复杂类型中,以定义数组类型。当您将复杂类型创建为struct/array时,该类型用于将该对象类型定义为数组

现在为

定义用户复杂类型
$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'),
      )
);

需要更多细节,请参阅本教程

嵌套数组教程