I have a string which can be
$string = "value.";
OR
$string = "value1, value2.";
I want to iterate through this string getting each item which are -> value
(in first example) and -> value1
AND value2
in the second (without the comma or the dot in the end).
I was thinking of;
- Replace the dot in the end.
- Check if there is any comma.
- If there is comma, split-explode using ", " and iterate through.
- If not, only one item so just use it.
Is this the right way of doing it?
I am new to PHP and trying to learn best practices and best ways of solving the issues.
Thank you.