[phpxmlrpc] Return Complex type

Gaetano Giunta giunta.gaetano at sea-aeroportimilano.it
Tue Jan 31 15:33:34 GMT 2006


Welcome to open source :)

To create a struct xmlrpcval:

$array = array('userid' => new xmlrpcval(1, 'int'), 'username' => new xmlrpcval('pippo', 'string'));
$val = new xmlrpcval($array, 'struct');

To create an array of structs, just iterate along the same lines:

$array = array('userid' => new xmlrpcval(1, 'int'), 'username' => new xmlrpcval('pippo', 'string'));
$val1 = new xmlrpcval($array, 'struct');
$array = array('userid' => new xmlrpcval(2, 'int'), 'username' => new xmlrpcval('goofy', 'string'));
$val2 = new xmlrpcval($array, 'struct');
$val = new xmlrpcval(array($val1, $val2), 'array');

This is of course a bit tedious and overly long.

An easier option would be, provided that you already have your data i a nicely formatted array, to do this:

$php_array = array (
  array('id' => 1, 'username' => 'pippo'),
  array('id' => 2, 'username' => 'goofy')
);
$val = php_xmlrpc_encode($php_array);

The inner arrays will be conveted into structs, since they use named keys.
The outher array is 'numerically indexed' and will be converted into an xmlrpc array.

Hope it helps
Gaetano Giunta

> -----Original Message-----
> From: phpxmlrpc-bounces at lists.usefulinc.com
> [mailto:phpxmlrpc-bounces at lists.usefulinc.com]On Behalf Of 
> Molese Kekana
> As Melf
> Sent: Tuesday, January 31, 2006 1:43 PM
> To: phpxmlrpc at lists.usefulinc.com
> Subject: [phpxmlrpc] Return Complex type
> 
> 
> Hi, I would like to know how do I return Array of Struct.
> for Example I would like to return from Table User.
> User_ID and User_Name but not just one record.
> I would like to return all my users with their User IDs.
> 
> By the way I'm more of a .Net Developer than PHP.
> I'm trying to move my organization to  PHP and open source.
> _______________________________________________
> phpxmlrpc mailing list
> phpxmlrpc at lists.usefulinc.com
> http://lists.usefulinc.com/cgi-bin/mailman/listinfo/phpxmlrpc
> 


More information about the phpxmlrpc mailing list