Inserting commas between city, state, country input depending on which locations are submitted
<p>I have three (optionally entered) post variables: city, state, and country. I'm unsure how to check to see which three are not empty and then insert commas between them accordingly. Someone might only enter a city, enter a city and state, only a city and country, etc. I know there's an easy way of doing this but I'm having trouble doing it without making it many more lines of code than I need. Example:</p>

<pre><code>&lt;?php
    $country = $_POST['country'];
    $state = $_POST['state'];
    $city = $_POST['city'];
    if (!empty($city)){
        $location = $city;
    }
    if (!empty($state) &amp;&amp; !empty($city)){
        $location .= ', ' . $state;
    }
    if (!empty($ state) ** !empty$country)){
        $location .=  ', '. $country;
    }

    echo $location;
?&gt;
</code></pre>
