xmlrpc array problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bugmenot
Forum Newbie
Posts: 23
Joined: Fri Oct 10, 2008 11:44 am

xmlrpc array problem

Post by bugmenot »

Hello all,

I am using xmlrpc-epi v. 0.51/PHP Version 5.2.8. My problem is really weird. I need return this array (don't ask why, it is just example):

Code: Select all

 
Array
(
    [3387112] => 3387112
    [3385570] => 3385570
)
 
here is my PHP code:

Code: Select all

 
function foo() {
    $in = array("3387112","3385570");
 
    $data = array();
 
    foreach($in as $value) {
        $data[ (string) $value ] = "$value";
    }
 
    return $data;
}
 
output is:

Code: Select all

 
Array
(
    [0] => 3387112
    [1] => 3385570
)
 
which is wrong. If somebody can help me, how to put INTEGERS as keys in output array, I will be really happy, or give me some help, I am really stuck. I tried double quotes, (string), strval and so on, I can not put any INT in output, I am not sure, if it is error of XMLRPC-EPI or...?
User avatar
phpserver
Forum Newbie
Posts: 22
Joined: Mon Oct 20, 2008 2:59 am
Location: Eastleigh,Nairobi

Re: xmlrpc array problem

Post by phpserver »

There is no error.It also happens in a mysql database.Let us say you want to fetch an array from mysql and you ain't got any data,you will get an array.Yours works just fine.
cavemaneca
Forum Commoner
Posts: 59
Joined: Sat Dec 13, 2008 2:16 am

Re: xmlrpc array problem

Post by cavemaneca »

They only way to put integers as keys is to create a new array and assign it both the key and value. either way, why would you want integers other the 0,1,2,...n for it anyway?
bugmenot
Forum Newbie
Posts: 23
Joined: Fri Oct 10, 2008 11:44 am

Re: xmlrpc array problem

Post by bugmenot »

thanks for fast replies guys. OK, the reason, why I want return INTEGERS as KEYS is quite simple, I have XMLRPC method GetComments(array($id, $id)) and it should be nice, if $id will be as KEY in returning array, right ? Now I have to add "_" there, but thats really stupid workaround. How I can achieve to have there Integers ? Please post some sample.

Code: Select all

 
   [status] => 200 OK
    [data] => Array
        (
            [_3387112] => Array
                (
                    [0] => Array
                        (
                            [IDSubtitle] => 3387112
                            [UserID] => 192696
                            [UserNickName] => neo_rtr
                            [Comment] => Greate Work. thank you
                            [Created] => 2008-12-14 17:20:42
                        )
 
                )
            [_3385570] => Array
                (
                    [0] => Array
                        (
                            [IDSubtitle] => 3385570
                            [UserID] => 745565
                            [UserNickName] => pee-jay_cz
                            [Comment] => Thank you.
                            [Created] => 2008-12-12 15:21:48
                        )
                    [1] => Array
                        (
                            [IDSubtitle] => 3385570
                            [UserID] => 754781
                            [UserNickName] => Guzeppi
                            [Comment] => You're welcome :)
                            [Created] => 2008-12-12 15:51:01
                        )
                )
        )
    [seconds] => 0.02
 
Post Reply