【问题标题】:Print nested array associative array php打印嵌套数组关联数组php
【发布时间】:2019-05-28 21:16:03
【问题描述】:

我正在循环遍历一个数组,我想打印该数组的一些

我可以打印索引为 0 的第一个数组,但我不能打印子数组。

  @foreach($data[0] as $k => $v)
  {{$v['bill_no']}}  //prints b-0002
   @foreach($v['customer_details'] as $kk => $vv)
    Customer Name : {{$vv['name']}} //gives the error
   @endforeach
 @endforeach

这是我的数组:

    Array ( [0] => 
    Array ( [0] => 
    Array ( [id] => 14 [customer_id] => 2 [referral_id] => 1 [sq_id] => 
    [bill_no] => b0002 [bill_date] => 07-09/2018 [payment_mode] => cash 
    [delivered_by] => tsr [net_total] => 15000
    [customer_details] => Array ( [id] => 2 [code] =>
    csdc [name] => jhon k [address] => mangalore [telephone] => cs [mobile] 
    => sd [tin] => sdc [gstin] => dsc
    [opening_balance] => 10000 [remarks] => sd [credit_limit] => 100 
    [bank_name] => HDFC [account_no] =>
    0022 [ifsc] => 5588 [account_name] => jhon [created_at] => 2018-08-13 
    22:04:10 [updated_at] => 2018-12-24
    09:39:00 ) [sold_items] => 

我要打印客户的名字

Name: {{$vv['name']}}

【问题讨论】:

  • 试试$v['customer_details']['name']

标签: php arrays laravel foreach


【解决方案1】:

试试这个:

@foreach($data[0] as $k => $v)
  {{$v['bill_no']}}  //prints b-0002
   @foreach($v['customer_details'] as $vv)    // As it is associative array, we are not going to use `$kk`
    Customer Name : {{$vv['name']}} //Now this should work.
   @endforeach
 @endforeach

【讨论】:

    猜你喜欢
    • 2017-09-18
    • 2018-07-04
    • 2011-09-19
    • 2018-11-16
    • 2013-10-22
    • 2017-05-24
    • 2020-08-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多