How to get field names at top of result array

Antony Jack :

Here is my Sample table... trying too get the field names on 0th array key...

enter image description here

Expected result array is...

Array
(
    [0] => Array
        (
            [id] => id
            [name] => name
            [country] => country
        )
    [1] => Array
        (
            [id] => 1
            [name] => a
            [country] => x
        )
    [2] => Array
        (
            [id] => 2
            [name] => b
            [country] => y
        )
)

Looking for Query...

Thanks in advance...

Sehdev :

You can use this:

@php
    $headings =  array_shift($array)
@endphp
<table>
 <tr>
     <td>{{$headings['id']}}<td>
     <td>{{$headings['name']}}<td>
     <td>{{$headings['country']}}<td>
 </tr>
 @foreach($array as $value)
  <tr>
      <td>{{$value['id']}}</td>
      <td>{{$value['name']}}</td>
      <td>{{$value['country']}}</td>
   <tr>
 @endforeach
</table>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=371861&siteId=1