Hi,
I have a tags field whose content looks like this:
----
Namepool: Zaphod,Arthur,Ford,Trillian,Marvin,Slartibartfast
----
I now need to get a random tag from this entry, and display that on the page as a string. I am struggling with this, what would be the best approach here?
Thanks!
Mike
Bunch of ways to do this, first one that comes to mind is something like this
// Convert to array and shuffle it
$tags = A::shuffle($page->namepool()->split());
// Grab the first item of the array
$tag = A::first($tags);
// Do something with it
echo $tag;
Just the job, thank you. I am having a very Friday sort of Friday!
1 Like