PHP:创建选择框时重复,只需要最高值的INT

时间:2012-11-09 21:38:59

标签: php zend-framework code-duplication

我在这里遇到一些重复问题, 我相信只要我的回报值,我就可以在任何时候剪辑欺骗 欺骗仍然是最大的内部价值。

这是代码图章:

    $unitList = Base_Client_Model::getBusinessUnitList(false, $selectedMarket, false, true);
    $marketListBox = $marketOptions = '';
    $marketList = array();

    for ($x = 1; $x <= $unitList['NUMBER_OF_BUSINESS_UNITS']; $x++) {
    $unitStr = 'BUSINESS_UNIT_' . $x . '_';

        $businessUnit = Base_Client_Model::getBusinessUnit($unitList[$unitStr . 'ID']);
        if ($unitList[$unitStr . 'ID'] && $unitList[$unitStr . 'ID'] != 42) {
            $marketListBox = "<option value='" . $unitList[$unitStr . 'ID'] . "'";
            if($selectedMarket == $unitList[$unitStr . 'ID']) {
                $marketListBox .= ' selected';
                $selectedMarket = 0;
            }

            $marketListBox .= ">&nbsp;&nbsp;&nbsp;" . preg_replace('/-Wimax/i', '', $unitList[$unitStr . 'NAME']) . "</option>\n";
            $marketList[$businessUnit->getElement('STATE')][] = $marketListBox;
        }
    }

    ksort($marketList);
    foreach($marketList as $key => $val) {
        $marketOptions .= "<option disabled='disabled'>&nbsp;</option><option disabled='disabled'>{$key}&#172;</option>\n" . implode($val);
    }

    $this->view->marketOptions = $marketOptions;

以下是退货示例:

<option disabled="disabled">&nbsp;</option><option disabled="disabled">WA¬</option>
<option value="56">&nbsp;&nbsp;&nbsp;Aberdeen</option>
<option value="82">&nbsp;&nbsp;&nbsp;Bellingham</option>
<option value="106">&nbsp;&nbsp;&nbsp;Everett</option>
<option value="109">&nbsp;&nbsp;&nbsp;Kitsap County</option>
<option value="102">&nbsp;&nbsp;&nbsp;Seattle</option>
<option value="105">&nbsp;&nbsp;&nbsp;Tacoma</option>
<option value="20">&nbsp;&nbsp;&nbsp;Tri-Cities</option>
<option value="173">&nbsp;&nbsp;&nbsp;Tri-Cities</option>
<option value="64">&nbsp;&nbsp;&nbsp;Wenatchee</option>
<option value="65">&nbsp;&nbsp;&nbsp;Yakima</option>
<option value="162">&nbsp;&nbsp;&nbsp;Yakima</option>

这是EXPECTED输出:

<option disabled="disabled">&nbsp;</option><option disabled="disabled">WA¬</option>
<option value="56">&nbsp;&nbsp;&nbsp;Aberdeen</option>
<option value="82">&nbsp;&nbsp;&nbsp;Bellingham</option>
<option value="106">&nbsp;&nbsp;&nbsp;Everett</option>
<option value="109">&nbsp;&nbsp;&nbsp;Kitsap County</option>
<option value="102">&nbsp;&nbsp;&nbsp;Seattle</option>
<option value="105">&nbsp;&nbsp;&nbsp;Tacoma</option>
<option value="173">&nbsp;&nbsp;&nbsp;Tri-Cities</option>
<option value="64">&nbsp;&nbsp;&nbsp;Wenatchee</option>
<option value="162">&nbsp;&nbsp;&nbsp;Yakima</option>

我相信答案与此相似

$unitList['BUSINESS_UNIT_' . $x . '_NAME'] != $unitList['BUSINESS_UNIT_' . $x + 1 . '_NAME']

1 个答案:

答案 0 :(得分:0)

需要Wimax和非Wimax市场的比较表,Wimax优先考虑

            if ($unitList['BUSINESS_UNIT_' . $x . '_NAME'] .'-Wimax' != $unitList['BUSINESS_UNIT_' . ($x + 1) . '_NAME']) {
                $marketListBox = "<option value='" . $unitList[$unitStr . 'ID'] . "'";
                if($selectedMarket == $unitList[$unitStr . 'ID']) {
                    $marketListBox .= ' selected';
                    $selectedMarket = 0;
                }

                $marketListBox .= ">&nbsp;&nbsp;&nbsp;" . preg_replace('/-Wimax/i', '', $unitList[$unitStr . 'NAME']) . "</option>\n";
                $marketListArray[$businessUnit->getElement('STATE')][] = $marketListBox;
            }