0

I have this code:

@foreach($files['folders'] as $file)
  @foreach(array_unique($file['file_name']) as $names)
    <tr><td>{{$names}}</td></tr>
  @endforeach
@endforeach

Returns null. I want array $file display only DISTINCT $file['file_name'].

Tim
  • 41,901
  • 18
  • 127
  • 145

1 Answers1

0

I think is better to solve this problem in your controller, try this:

//TheController.php
... whatever code you have in controller...
$seen = [];
$unique_files = [];
foreach($files['folders'] as $file)
    if(!isset($seen[$file['file_name']]) {
       $seen[$file['file_name'] = true;
       $unique_files[] = $file;
    }
}
$files['folders'] = $unique_files;

//Then pass $files as usual to your view

In your template file now you have only unique values:

@foreach($files['folders'] as $file)
   <tr><td>{{$file['file_name']}}</td></tr>
@endforeach

I hope this works for you

Edgar Orozco
  • 2,722
  • 29
  • 33