0

I've been trying multiple things and for the life of me can not get this to work. I'm beginning to think it maybe isn't possible at this point.

So I have a SOAP API I'm sending this array too. Below is the code I currently have that works, but does not send the multiple values. It just uses the last one as it overwrite the previous.

Looking at this thread, what I'm doing should work?

$my_array['sn'] = "234234232";
$my_array['arrayparams'] = array(
'Param' => array( 'Name' =>     'sending_key', 'Value' => 'blah',), 
'Param' => array( 'Name' => 'sending_key2', 'Value' => '2',),
);
$my_array['push'] = true; 
$my_array['endsession'] = false;

returns:

array(4) {
  ["sn"]=>
  string(12) "234234232"
  ["arrayparams"]=>
  array(1) {
    ["Param"]=>
    array(2) {
      ["Name"]=>
      string(61) "sending_key2"
      ["Value"]=>
      string(1) "2"
    }
  }
  ["push"]=>
  bool(true)
  ["endsession"]=>
  bool(false)
}

I'm just having a time getting it to send this instead:

array(4) {
  ["sn"]=>
  string(12) "234234232"
  ["arrayparams"]=>
  array(2) {
    ["Param"]=>
    array(2) {
      ["Name"]=>
      string(61) "sending_key"
      ["Value"]=>
      string(1) "blah"
    }
    ["Param"]=>
    array(2) {
      ["Name"]=>
      string(61) "sending_key2"
      ["Value"]=>
      string(1) "2"
    }
  }
  ["push"]=>
  bool(true)
  ["endsession"]=>
  bool(false)
}

The 'Param' array is very strict and has to have this value, I can not change to 'Param2' to get it to work.

4
  • 2
    Possible duplicate of PHP Associative Array Duplicate Key? Commented Apr 8, 2016 at 16:06
  • It's not possible to have duplicate keys in an associative array, it makes no sense. Commented Apr 8, 2016 at 16:10
  • Yeah, but the API requires it to be sent this way which blew my mind. Commented Apr 8, 2016 at 16:11
  • I suspect you're misreading the API documentation. Got a link? Commented Apr 8, 2016 at 16:12

2 Answers 2

1

can you do this?

$my_array['arrayparams'] = array(
    array('Param' => array( 'Name' =>     'sending_key', 'Value' => 'blah',)), 
    array('Param' => array( 'Name' => 'sending_key2', 'Value' => '2',)),
);
Sign up to request clarification or add additional context in comments.

1 Comment

But obviously it's the right answer, because user1628515 wrote "perfect solution" to the answer of Mike, who basically sent the same answer
0

The problem is you can't have the key 'Param' set in more than one key.

You would need to define 'Param' as an actual array, instead of as multiple keys within in array.

like so...

$my_array['Param'] = [
    ['Name' => 'sending_key', 'Value' => 'blah'],
    ['Name' => 'sending_key2', 'Value' => '2']
];

2 Comments

Up votes for this one, perfect solution! Thanks Mike!
please accept as solution if this works for you. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.