Numeric Drop-down With PHP ranges

Here is an easy way to generate form numeric drop-down with ranges.
       $form = new Zend_Form();

        $ranges = array( 
            range(1, 20, 1) , 
            range(30, 100, 10) , 
            range(200, 1000, 100) 
        );
        $a = array();
        foreach ( $ranges as $range ) {
            foreach ( $range as $r ) {
                $a[$r] = $r;
            }
        }
        
        $form->addElement('select', 'quantity', array( 
            'label' => 'Quantity' , 
            'required' => false , 
            'class' => 'form-control' , 
            'multiOptions' => array( 
                '' => '--Select--' 
            ) + $a 
        ));

Please note that the ranges are with different steps. Here is the result:

Comments

Popular posts from this blog

Enable pgpass under Windows 7