Grouping ZIP codes into ranges There is a clear pattern as to what the number values would be. And this has a starting interval and known start and end value. Though the end may change, it seems simpler to set the values and do some magical loop. Any better formats would be appreciated. The sets are what I would have gone with if I could have gotten the loop to work correctly.

&lt;?php
$setStart =5000;
$setEnd = 95000;
$setInterval = 5000;

    //Enter your code here, enjoy!

    foreach($zips as $zipcode) {
    $zip = $zipcode['zip'];
    $zipInt = intval($zipcode['zip']);
    $org_ids = $zipcode['orgs'];
    $org_ids = explode(",",$org_ids);
    if (!empty($org_ids)) {
        if ($zipInt &lt; 5000) {
            $zips00_array[$zip] = $org_ids;
        }
        if ($zipInt &gt;= 5000 &amp;&amp; $zipInt &lt; 10000) {
            $zips05_array[$zip] = $org_ids;
        }
        if ($zipInt &gt;= 10000 &amp;&amp; $zipInt &lt; 15000) {
            $zips10_array[$zip] = $org_ids;
        }
        if ($zipInt &gt;= 15000 &amp;&amp; $zipInt &lt; 20000) {
            $zips15_array[$zip] = $org_ids;
        }
        if ($zipInt &gt;= 20000 &amp;&amp; $zipInt &lt; 25000) {
            $zips20_array[$zip] = $org_ids;
        }
        if ($zipInt &gt;= 25000 &amp;&amp; $zipInt&lt; 30000) {
            $zips25_array[$zip] = $org_ids;
        }
        if ($zipInt &gt;= 30000 &amp;&amp; $zipInt &lt; 35000) {
            $zips30_array[$zip] = $org_ids;
        }
        if ($zipInt &gt;= 35000 &amp;&amp; $zipInt &lt; 40000) {
            $zips35_array[$zip] = $org_ids;
        }
        if ($zipInt &gt;= 40000 &amp;&amp; $zipInt &lt; 45000) {
            $zips40_array[$zip] = $org_ids;
        }
        if ($zipInt &gt;= 45000 &amp;&amp; $zipInt &lt; 50000) {
            $zips45_array[$zip] = $org_ids;
        }
        if ($zipInt &gt;= 50000 &amp;&amp; $zipInt &lt; 55000) {
            $zips50_array[$zip] = $org_ids;
        }
        if ($zipInt &gt;= 55000 &amp;&amp; $zipInt &lt; 60000) {
            $zips55_array[$zip] = $org_ids;
        }
        if ($zipInt &gt;= 60000 &amp;&amp; $zipInt &lt; 65000) {
            $zips60_array[$zip] = $org_ids;
        }
        if ($zipInt &gt;= 65000 &amp;&amp; $zipInt &lt; 70000) {
            $zips65_array[$zip] = $org_ids;
        }
        if ($zipInt &gt;= 70000 &amp;&amp; $zipInt &lt; 75000) {
            $zips70_array[$zip] = $org_ids;
        }
        if ($zipInt &gt;= 75000 &amp;&amp; $zipInt &lt; 80000) {
            $zips75_array[$zip] = $org_ids;
        }
        if ($zipInt &gt;= 80000 &amp;&amp; $zipInt &lt; 85000) {
            $zips80_array[$zip] = $org_ids;
        }
        if ($zipInt &gt;= 85000 &amp;&amp; $zipInt &lt; 90000) {
            $zips85_array[$zip] = $org_ids;
        }
        if ($zipInt &gt;= 90000 &amp;&amp; $zipInt &lt; 95000) {
            $zips90_array[$zip] = $org_ids;
        }
        if ($zipInt &gt;= 95000) {
            $zips95_array[$zip] = $org_ids;
        }
    }
}
I think you could use a one-liner like:

$zip_arr_id = floor(($zipInt/1000)/5 )*5;


which could correspond to the $zips${$zip_arr_id}_array (unsure if this is exactly right) that you're saving the org ID's to. Look into variable variables in php.

Riffing on this idea could save you a lot of lines in your code.