I'm trying to make a function, that will spot how many times, different words occured in a text. The thing is, that I would like bundle together similar words (and nicknames).
I have this array of interesting words (that I manually have defined):
$interesting_words = [
'test' => [
'number_of_occurances' => 0,
'connected_words' => [
'TEST',
'TESTER',
'TESTING'
]
],
'foobar' => [
'number_of_occurances' => 0,
'connected_words' => [
'FOO',
'FOOBAR',
'BAR'
]
]
]
Example text.
Lorem ipsum TEST sit amet, consectetur TESTER elit. Sed in turpis dui. Maecenas venenatis FOOBAR facilisis. Quisque dictum, diam consequat mollis TESTING, orci tellus aliquet nisl, BAR molestie FOO augue at est. In TESTING vehicula lectus. Curabitur ac varius ligula. Pellentesque orci urdna.
Desired output.
Number of occurances for 'test': 4
Number of occurances for 'foobar': 3
Are there a smart way of doing this without having 1.000.000 for-loops?
I'm making the function in Laravel, if that's any help.