Jump to content

creating an array / change array key


konst1977

Recommended Posts

Hi!

 

I have two arrays - $cab & $cab2, then I have to combine them into one array $temparray & the keys should be "addressbook". Currently I use array("addressbook" => $cab, $cab2), but as a result only one key has value "addressbook" another one has value "0" (pls see the pic). How to create an array with both keys "addressbook" or how to rename "0" to "addressbook"? Thanks in advance (php 5.2.x).

 

$cab = array("defaultBilling" => "true", "defaultShipping"=> "false", "label" => $streetn, "addressee" => $fullname, "addr1" => $streetn, "phone" => $phonen, "state" => $staten, "zip" => $zipn, "country" => "_unitedStates", "city" => $cityn);

 

$cab2 = array("defaultBilling" => "false", "defaultShipping"=> "true", "label" => $streetn2, "addressee" => $fullname2, "addr1" => $streetn2, "phone" => $phonen, "state" => $staten2, "zip" => $zipn2, "country" => "_unitedStates", "city" => $cityn2);

 

$temparray = array("addressbook" => $cab, $cab2);

 

[attachment deleted by admin]

Link to comment
Share on other sites

Sorry,

 

so I have two arrays - $cab & $cab2 each filled with 10 pairs of string values/keys (basically they are two addresses - shipping a billing ). Then I have to combine them into one array (to send it to a web-service). This array should have two entries with both keys equal to "addressbook" and values respectively arrays ($cab & $cab2). Since I'm a PHP newbie I don't know what type of an array (associative, list, etc...), hopefully you'll be able to figure it from a picture (picture is from Zend Studio debugger). I'm able to create the array I need but the problem is that one key value is "0" instead of "addressbook" (as you can see on the attached picture) and the webservice doesn't accept it. So how to make the second key to be "addressbook" instead of "0".

 

 

To simplify the example, let's say:

 

$cab = array("addressee" => "John Sheldon", "addr1" => "3638 25th Avenue", "city" => "New York");

$cab2 = array("addressee" => "Gavin Newsom", "addr1" => "15 Market St.", "city" => "San Francisco");

 

$temparray = array("addressbook" => $cab, $cab2);

 

Tks a lot!

Link to comment
Share on other sites

hmm... gotcha... what should I do then, the web service need this sort of soap request (generated with .net):

 

addressbookList

{

addressbook

{

boolean  defaultShipping  =  false

boolean  defaultBilling  =  true

string  label  =  Shipping Address

string  attention  =  John W Sheldon

string  addressee  =  John W Sheldon

int  phone  =  345345555

string  addr1  =  addrrss77

string  city  =  SF

int  zip  =  43459

string  state  =  _arizona

}

addressbook

{

boolean  defaultShipping  =  true

boolean  defaultBilling  =  false

string  label  =  Shipping Address2

string  addressee  =  Test

integer  phone  =  3434535345

string  addr1  =  address test

string  city  =  New York

int  zip  =  78901

string  state  =  _alaska

}

}

 

however, the custom libraries which I use to generate soap requests need arrays, and my array generated from PHP looks like and it's rejected by the web service:

 

addressbookList

{

addressbook

{

boolean  defaultBilling  =  true

boolean  defaultShipping  =  false

string  label  =  address15

string  addressee  =  John X Sheldon

string  addr1  =  address15

integer  phone  =  3453453455

string  state  =  _california

int  zip  =  94110

string  country  =  _unitedStates

string  city  =  SF

}

__numeric_0

{

boolean  defaultBilling  =  false

boolean  defaultShipping  =  true

string  label  =  address2

string  addressee  =  John2 X Sheldon2

string  addr1  =  address2

integer  phone  =  3453453455

string  state  =  _alaska

int  zip  =  12345

string  country  =  _unitedStates

string  city  =  SF2

}

}

 

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.