underline the nth word of a string based on an array in php/laravel

Published

I have passed some paginated data to my blade view like this:

<div>
     @foreach ($result as $item)
        {{ $item->text}} :
        <br>
     @endforeach
     {{ $result->links() }}
</div>

//outputs 3 strings

I have an array with 3 elements that contains the respective locations of each word in each string that should be "underlined":

array:3 [▼
  0 => 19
  1 => 5
  2 => 3
]

So 19 means, the 19th word of the first string that will be underlined. Likewise 5 and 3 mean the 5th and the 3rd words in the second and the third string.

So, what should I write in my loop to underline nth word in a string based on a given array?

Can you please give me a tip?

Source: Laravel

Published
Categorised as laravel, php, replace, string Tagged , , ,

Answers

Leave a Reply

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq