title: How to return nested array using Nusoap complextype in PHP?
body: <p>I am writing a web service in php using nusoap library. I can return simple variables such as string, integer and also only one complextype which is struct. But I can not return array of structs. I research nearly all example in a week about this but it doesn't work. So where I am going wrong?</p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>$server-&gt;wsdl-&gt;addComplexType('userSitesData','complexType','struct','all','',
          array(
                  'id' =&gt; array('name'=&gt;'id','type'=&gt;'xsd:int'),
                  'siteName' =&gt; array('name'=&gt;'siteName','type'=&gt;'xsd:string'),
                  'workPlace' =&gt; array('name'=&gt;'workPlace','type'=&gt;'xsd:string'),
                  'situation' =&gt; array('name'=&gt;'situation','type'=&gt;'xsd:string')
          )
  );
  // *************************************************************************
  // Complex Array ++++++++++++++++++++++++++++++++++++++++++
  $server-&gt;wsdl-&gt;addComplexType(
          'userSiteDataList',
          'complexType',
          'array',
          '',
          'SOAP-ENC:Array',
          array(),
          array(
              array(
                  'ref' =&gt; 'SOAP-ENC:arrayType',
                  'wsdl:arrayType' =&gt; 'tns:userSitesData[]'
              )
          ),
          'tns:userSiteDataList'
  );
  //Struct of above array
  $server-&gt;wsdl-&gt;addComplexType(
      'UserSiteList',
      'complexType',
      'struct',
      'all',
      '',
      array(
          'list' =&gt; array('name'=&gt;'list','type'=&gt;'tns:userSiteDataList')
      )
  );
  // *************************************************************************
  $server-&gt;register(
                  "userSitesList",
                  array('name' =&gt; 'xsd:int'),
                  array('return' =&gt; 'tns:UserSiteList'),
                  // namespace:
                  $namespace,
                  // soapaction: (use default)
                  false,
                  // style: rpc or document
                  'rpc',
                  // use: encoded or literal
                  'encoded',
                  // description: documentation for the method
                  'Use this service to list buildingsites belong given user.');
  // *************************************************************************
  //RETURN USER'S BUILDING SITES LIST
  function userSitesList($id)
  {
      $list=array();
      $conn=openConnection();
      // Check connection
      if ($conn-&gt;connect_error)
      {
          $error=("Connection failed: " . $conn-&gt;connect_error);
      }   
      /* create a prepared statement */
      $stmt =  $conn-&gt;stmt_init();
      // prepare and bind
      if($stmt = $conn-&gt;prepare("SELECT id, siteName, workPlace, situation FROM sertkatestdatabase.buildingsite JOIN userworkssites ON  sertkatestdatabase.userworkssites.userId=? WHERE sertkatestdatabase.buildingsite.id=sertkatestdatabase.userworkssites.buildingsiteId"))
      {
          $stmt-&gt;bind_param("i", $id);
          // execute query
          $stmt-&gt;execute();
          // bind result variables //
          $stmt-&gt;bind_result($resultId,$resultSiteName,$resultWorkPlace,$resultSituation);
          // fetch value //       
          while ( $stmt-&gt;fetch() ) 
          {
              $list[]=array('id' =&gt; $resultId, 'siteName' =&gt; $resultSiteName, 'workPlace'=&gt;$resultWorkPlace, 'situation'=&gt;$resultSituation);
              //array_push($list,array('id' =&gt; 1, 'siteName' =&gt; 'test', 'workPlace'=&gt;'test', 'situation'=&gt;'test'));// I also try this. It doesn't work.
          }
          // close statement
          $stmt-&gt;close();
      }   
      $conn-&gt;close();
       // Create List
      $myList = array('list'=&gt;$list);
      return $myList;
  }
  </code></pre>