打印嵌套数组关联数组php

时间:2019-01-02 07:27:48

标签: php arrays laravel foreach

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

我可以打印索引为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']}}

1 个答案:

答案 0 :(得分:0)

尝试一下:

@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