'how to show combine Array in Datatable

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" class="table m-0 table table-bordered table-hover table" 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



Solution 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1