Jump to content

PHP Associative Array internal structure


bobe1059

Recommended Posts

I am an ASP.NET developer and I have to call a soap methed written in PBP that takes an argument required an associative array

such as

 

$prices = array( 'Tires'=>'test1', 'Spark Plugs'=>'test2' );

 

can yoiu tell me what the internal representation is of the above

Link to comment
Share on other sites

tell me if I am wrong.... but PHP associative arrays are a language specific data structures which other languages know nothing about and can not re-create (without knowledge of the internal structure). So a web service written in PHP where an argument required an associative arraycan not be consumed by any other client (ASP.NET is the case) other than PHP clients.

 

Link to comment
Share on other sites

You can tell PHP to return any format ASP.NET understands. If ASP.NET understands JSON encoded strings then you can communicate with ASP.NET using JSON-encoded messages or XML or CSV or .. I don't see how the internal structure of an array is important since you are treating it as a webservice.

Link to comment
Share on other sites

Actually its the other way around. I need to send data to the PHP web service and its requires an associative array for a particular argument. The problem is that no matter what I do (JSON ,XML etc) the PHP side can not read it as an array. I have tried Dictionaries, Array Lists, name Value pairs, VB arrays. I  am trying to tell them that they need to change the PHP web servce to accept serializd data such as XML  so that non-PHP clients can consume the web service.

Link to comment
Share on other sites

Alternately

 

service.php?csv=val1,val2,val3,val4

 

$array = explode( ',', $_GET['csv'] )

 

Keep in mind, order CAN/WILL become a factor here.

 

To avoid this, you can create an associative array

 

service.php?var[foo]=bar&var[bar]=foo

Link to comment
Share on other sites

I dont have any control over the PHP code here is wha the doc says:

 

Notice the array in the 3rd argument. ASP.NET does not have an "array(=>)" object. No matter what I pass the PHP side returns an error

 

recordUpdate:

recordUpdate(public_id,[contact_id],data)

 

This function will update all data for a record that is not associated with a one to many record.  You must put your public_id or you will get an access error.  If you put a contact_id into the function then you will update a record.  If the contact_id is blank, then you will insert a new record.  The data variable is an array of data you want to update using the DB name as the key.

 

An example of this function would be:

 

Insert:

$c = recordUpdate('public','',array('firstname'=>'John',

'lastname'=>'Doe'));

 

returns:

$c = “new contact_id”

 

$c = recordUpdate('public','1',array('firstname'=>'John',

'lastname'=>'Doe'));

returns:

$c = 1

 

If an error occurs, then recordUpdate will return a text message trying to explain what went wrong.

 

 

 

Link to comment
Share on other sites

outside data?

 

 

I have tried many ways to populate the array argument ..here is a json serialized example in VB.NET. below returns a soft error from the PHP web service saying it cant read the array data.

 

trying to populate array("Contact1Email"=>"mdrake@pwrx.com")

 

Dim c As New com.contactbeacon.cbapiService

    Dim json As String = "a:1:{s:13:""Contact1Email"";s:15:""mdrake@pwrx.com"";}"

Dim retval As Object = c.recordUpdate("public string ", json)

Link to comment
Share on other sites

Oh, I see what's going on here.

 

Your best bet is to get the programmers to allow serialized data.

 

Beyond that, this is more of a SOAP issue than PHP. If .NET is encoding the array properly, then it's possible the PHP script isn't translating them back.

Link to comment
Share on other sites

You say you have no control over the PHP the code yet you come up with an example like this:

 

$c = recordUpdate('public','',array('firstname'=>'John',
            'lastname'=>'Doe'));

 

What do you not control? The code of recordUpdate()? What prohibits you from writing:

 

$c = recordUpdate('public','',$_GET['myarray']);

 

Or are you calling this using SOAP? RPC? Help me help you, give me the information I need, don't let me drag it out of you I have no magic ball I can look into.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.