douou6696
2016-04-08 16:05
浏览 16
已采纳

具有相同键的多个数组的PHP多维数组?

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. Thanks in advanced!

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

  • dongruoqiong9017 2016-04-08 16:10
    最佳回答

    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']
    ];
    
    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题