簡體   English   中英

打印嵌套數組關聯數組php

[英]Print nested array associative array php

我正在遍歷一個數組 ,我想打印該數組的一些

我可以打印第一個索引為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']}}

試試看:

@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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM