Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 数组值作为zend form select元素中的键_Arrays_Zend Form_Zend Form Element - Fatal编程技术网

Arrays 数组值作为zend form select元素中的键

Arrays 数组值作为zend form select元素中的键,arrays,zend-form,zend-form-element,Arrays,Zend Form,Zend Form Element,我有一个zend表单,在该表单中,我创建了一个选择框,如下所示: $e = new Zend_Form_Element_Select('user_status'); $e->setLabel('Status'); $e->addMultiOptions(Model_User::$STATUS); $e->setRequired(false); $this->addElement($e); public static $STATUS = array( 1 =&

我有一个zend表单,在该表单中,我创建了一个选择框,如下所示:

$e = new Zend_Form_Element_Select('user_status');
$e->setLabel('Status');
$e->addMultiOptions(Model_User::$STATUS);
$e->setRequired(false);
$this->addElement($e);
public static $STATUS = array(
    1   =>  'creating user',
    2   =>  'creating book',
    3   =>  'book created',
    4   =>  'book send'
);
<select name="user_status" id="user_status">
   <option value="creating user" label="creating user">creating user</option>
   <option value="creating book" label="creating book" selected="selected">creating book</option>
   <option value="book created" label="book created">book created</option>
   <option value="book send" label="book send">book send</option>
</select>
Model_User::$STATUS数组如下所示:

$e = new Zend_Form_Element_Select('user_status');
$e->setLabel('Status');
$e->addMultiOptions(Model_User::$STATUS);
$e->setRequired(false);
$this->addElement($e);
public static $STATUS = array(
    1   =>  'creating user',
    2   =>  'creating book',
    3   =>  'book created',
    4   =>  'book send'
);
<select name="user_status" id="user_status">
   <option value="creating user" label="creating user">creating user</option>
   <option value="creating book" label="creating book" selected="selected">creating book</option>
   <option value="book created" label="book created">book created</option>
   <option value="book send" label="book send">book send</option>
</select>
输出如下:

<select name="user_status" id="user_status">
   <option value="0" label="creating user">creating user</option>
   <option value="1" label="creating book" selected="selected">creating book</option>
   <option value="2" label="book created">book created</option>
   <option value="3" label="book send">book send</option>
</select>
现在我希望输出是这样的:

$e = new Zend_Form_Element_Select('user_status');
$e->setLabel('Status');
$e->addMultiOptions(Model_User::$STATUS);
$e->setRequired(false);
$this->addElement($e);
public static $STATUS = array(
    1   =>  'creating user',
    2   =>  'creating book',
    3   =>  'book created',
    4   =>  'book send'
);
<select name="user_status" id="user_status">
   <option value="creating user" label="creating user">creating user</option>
   <option value="creating book" label="creating book" selected="selected">creating book</option>
   <option value="book created" label="book created">book created</option>
   <option value="book send" label="book send">book send</option>
</select>
长话短说:
我希望数组值是zend表单中的键。如何在不更改状态数组键的情况下实现这一点。

只需预处理模型用户::$status var

$statuses = array();
foreach (Model_User::$STATUS as $status) {
    $statuses[$status] = $status;
}
然后设置多个选项

$e->addMultiOptions($statuses);