PHP Struct

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
asprsai
Forum Newbie
Posts: 2
Joined: Fri Nov 26, 2010 10:43 pm

PHP Struct

Post by asprsai »

hello guys.,

I need small help from. I am a java developer and am not well acquainted with php. I am developing a java application which calls a php web service (sugar CRM soap webservice)., so one of the web service method (login) takes a php struct as a parameter, user_auth which has three parameters username, password and version, all of them are strings. Can any one tell me what will be the output structured like when we print out the user_auth struct.

I tried:
1) String user1 = "user_auth{username=will; password=18218139eec55d83cf82679934e5cd75; version=1.0;}";
2) String user2 = "{'user_auth':{'username':'will','password':'18218139eec55d83cf82679934e5cd75', 'version':'1.0'}}";

Does any of the above strings match the output of a struct in php? If not what should it be like??

This would be of a great help for me if any one can tell me whats the right now.

Thanks,
aspr
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: PHP Struct

Post by califdon »

PHP doesn't use the concept of a struct, as C does (and probably Java, I'm not a Java programmer). I believe that if you are expecting a struct, PHP probably sends an array, but someone else is likely to give you a more reliable answer.
asprsai
Forum Newbie
Posts: 2
Joined: Fri Nov 26, 2010 10:43 pm

Re: PHP Struct

Post by asprsai »

If its an array which one of those closely match the java strings?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: PHP Struct

Post by califdon »

asprsai wrote:If its an array which one of those closely match the java strings?
I'm not sure what you mean. As far as I know, an array is the same in any language. It's a data structure that can be indexed either by its position (array[0], array[1], etc. for a one-dimensional array) or by a key value (array['key1']['red'], array['key2']['green'], etc. for a 2-dimensional array).
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: PHP Struct

Post by Christopher »

All scalars in PHP are essentially strings. You can use an associative array or an object to hold the values. It looks like you are using JSON above describing objects. PHP has a JSON library that can convert either arrays or objects.
(#10850)
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: PHP Struct

Post by McInfo »

If this login() function is the one in question, I believe the answer is

Code: Select all

$user_auth = array (
    'username' => 'will',
    'password' => '18218139eec55d83cf82679934e5cd75',
    'version' => '1.0'
);
Whitespace is irrelevant.
asprsai wrote:output of a struct
I interpreted that as "syntax of an array".
Post Reply