duanqianwei2485 2019-07-04 18:51
浏览 55
已采纳

我该如何处理?

Let´s see some code to explain better: I made a request to a WS as showing bellow:

        $idERP = 1;
        $grupoEcota = new \SoapClient($url);
        $paramExtrato = array(
            'sGrupo' => $request->sGrupo,
            'iCota' => $request->iCota,
            'iIdERP' => $idERP,
        );
        $responseExtrato = $grupoEcota->ROS_ExtratoContaCorrente($paramExtrato);
        $grupoEcota = $responseExtrato->ExtratoContaCorrente;

I get a response from a WS witch looks like this from dd(die and dump):


$dados[] = $grupoEcota->{'PARCELAS-PAGAS'};
        dd($dados);

array:1 [▼
  0 => {#784 ▼
    +"PARCELA-PAGA": array:21 [▼
      0 => {#783 ▼
        +"NUMERO-PARCELA": 48
        +"DATA-VENCIMENTO": "20170818"
        +"DATA-PAGAMENTO": "20170919"
        +"VALOR-PARCELA": 580.28
        +"HITORICO-PARCELA": ""
        +"PERC-PAGO": 3.491
      }
      1 => {#771 ▶}
      2 => {#781 ▶}
      3 => {#780 ▶}
      4 => {#779 ▶}
      5 => {#778 ▶}
      6 => {#777 ▶}
      7 => {#776 ▶}
      8 => {#775 ▶}
      9 => {#774 ▶}
      10 => {#773 ▶}
      11 => {#772 ▶}
      12 => {#757 ▶}
      13 => {#770 ▶}
      14 => {#769 ▶}
      15 => {#768 ▶}
      16 => {#767 ▶}
      17 => {#766 ▶}
      18 => {#765 ▶}
      19 => {#764 ▶}
      20 => {#763 ▶}
    ]
  }
]

I need to get only the first "DATA-VENCIMENTO": "20170818" item. How do I do it, please?

  • 写回答

2条回答 默认 最新

  • drtoaamk20278 2019-07-04 19:54
    关注

    Firstly you are dealing with an array, lets fetch that first element out (my assumption is there will only be one element.).

    $data= $data[0];
    

    Now we have a key value array, we can now fetch out the PARCELA-PAGA.

    $parcels = $data{'PARCELA-PAGA'];
    

    Multiple objects in a array is the next level, this means that there are in each object data, so i would use array_pluck to get these elements out.

    $vencimento = array_pluck($parcels, 'DATA-VENCIMENTO');
    

    If you do not care about multiple data fields, you could simply take the first element. Be careful this data is not an array, but an object.

    $vencimento = $parcels[0]->DATA-VENCIMENTO;
    

    Which should result in a result looking like this.

    [""20170919"", "20171019", ...]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R