简体   繁体   English

是否有可能在php中使用相同的键创建数组?

[英]is it possible to create array with same key in php?

i'm having problem with sendin soap request using php,xml code looks like below: ** 我在使用php,xml代码发送sendo soap请求时遇到问题,如下所示:**

<list> 
  <ExtIdList>
   <serviceExtId set="true">
   <value>$value1</value>
  </serviceExtId>
  <ExtIdType set="true">
   <value>1</value>
  </ExtIdType>
  </ExtIdList>

  <ExtIdList>
   <serviceExtId set="true">
   <value>$value2</value>
  </serviceExtId>
  <ExtIdType set="true">
   <value>2</value>
  </ExtIdType>
  </ExtIdList>
 </list>

** **

the problem is here i can't translate it to array, if translate it to array here will be 2 same keys. 问题是这里我无法将其转换为数组,如果将其转换为数组,将是2个相同的键。 is there any way to send such soap request using php? 有什么方法可以使用php发送这种肥皂请求吗?

Try this (I'm not sure it applies to your situation, but it worked for me when I was sending to XERO api multiple phones) - something like nested arrays: 试试这个(我不确定它是否适用于您的情况,但是当我向XERO api发送多部电话时,它对我有用)-类似于嵌套数组:

$phones =
array(
    array(
        'Phone' => array(
            'PhoneType' => 'DEFAULT',
            'PhoneNumber' => $values['phone']
    )),
    array(
        'Phone' => array(
            'PhoneType' => 'MOBILE',
            'PhoneNumber' => $values['mobile']
    ))
);

In your case replace 'Phone' key with 'ExtIdList' 在您的情况下,将'Phone'键替换为'ExtIdList'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM