PHP iterating through a simple comma separated list
<p>I have a string which can be</p>

<pre><code>$string = "value.";
</code></pre>

<p>OR</p>

<pre><code>$string = "value1, value2.";
</code></pre>

<p>I want to iterate through this string getting each item which are -> <code>value</code> (in first example) and -> <code>value1</code> AND <code>value2</code> in the second (without the comma or the dot in the end). </p>

<p>I was thinking of;</p>

<ol>
<li>Replace the dot in the end.</li>
<li>Check if there is any comma.</li>
<li>If there is comma, split-explode using ", " and iterate through.</li>
<li>If not, only one item so just use it.</li>
</ol>

<p>Is this the right way of doing it? </p>

<p>I am new to PHP and trying to learn best practices and best ways of solving the issues.</p>

<p>Thank you.</p>
