Compare similar values from several file's text fields and sort

Hi,

Here is what i want to achieve:

I have a standard portfolio structure projects>project>files

Files can be images, pdf or videos.

i have added a “author” text field to the files blueprint.

Now i wanna output a “files credits” on the project page. Let’s say the project have 3 photos, both of them have been made by “John Doe”, and the other one have been made by “Lucy Sky”. The user enter the ccorresponding author name for each file. I’d like to automatically display :
“Credit : John Doe, Lucy Sky”, without repeating “John Doe” two times…

Is this possible?

If you just want to output all authors for all images without repeating anything, you can get an array of all unique authors of a given page’s images like this:

<?php
$authors = $page->images()->pluck('author', ',', true); // true will only get unique values
foreach($authors as $author) {
  echo $author;
}

or

<?php

$authors = $page->images()->pluck('author', ',', true); // true will only get unique values

echo "Credit: " . implode(',', $authors);

If you want to sort them, you can use one of PHP’s array sort methods, see http://php.net/manual/en/function.sort.php

@jbman Did this answer your question?

Sorry, yes this worked thanks !