oz11 Posted August 19, 2023 Share Posted August 19, 2023 (edited) Hey, I'm having trouble here... how do i modify this code so that the following element is displayed ahead of each "word" in the output..[see bellow]. Also is there a way to count the number of times the occurrences take place (1,2,3 etc). Help. Quote <i class="fa fa-tag" aria-hidden="true"></i> $str = "Yogurt (Milk), Strawberries (11%), Sugar, Water, Stabilisers: Pectins, Guar Gum, Flavourings, Acidity Regulator: Citric Acid, Yogurt (Milk), Peach (9%), Sugar, Water, Apricot (3%), Stabilisers: Pectins, Guar Gum, Acidity Regulator: Citric Acid, Flavourings"; $new_str = array_unique(array_map('trim', explode(',', $str))); $string = implode(',', $new_str); echo $string; Edited August 19, 2023 by oz11 Quote Link to comment Share on other sites More sharing options...
requinix Posted August 19, 2023 Share Posted August 19, 2023 If you need a count then array_unique won't help you. There is one that can help, though, in this list. To output something before each "word", what have you tried so far? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.