Home > OS >  how to show combine Array in Datatable
how to show combine Array in Datatable

Time:03-18

I am new to Laravel and trying to show combinearray in the datatable but now able to get the output.

Code for Merged Array

$expdataforyear= array();
$expdataforyear = array_combine($getmonths, $expdata);

Array Output

"Apr-2021" => 0
"May-2021" => 0
"Jun-2021" => 0
"Jul-2021" => 0
"Aug-2021" => 0
"Sep-2021" => 0
"Oct-2021" => "285"
"Nov-2021" => "300"
"Dec-2021" => "250"
"Jan-2022" => "180"
"Feb-2022" => "315"
"Mar-2022" => "300"

Datatable

<table id="expensetable"  data-order='[[ 0, "desc" ]]'>
                                      <thead>
                                        <tr>
                                          <th>Months</th>
                                          <th>Amount (Rs.)</th>
                                        </tr>
                                      </thead>
                                      <tbody>
                                        @foreach ($expdataforyearas $item )
                                          <tr> 
                                            <td>{{$item->???}}</td>
                                            <td>{{$item->???}}</td>
                                          </tr>
                                        @endforeach
                                      </tbody>
                                    </table>

Thanks in Advance

CodePudding user response:

You can loop an array in your blade by using the Blade directive @foreach Inside this directive you can prinbt out. The problem in your code comes from the syntax in the foreach function. @foreach($arr as $item) ... @endforeach

@foreach ($expdataforyearas as $itemKey => $itemValue )
  <tr> 
    <td>{{ $itemKey }}</td> 
    <td>{{ $itemValue }}</td> 
  </tr>
@endforeach
  • Related