<?php
$types_size=sizeof($types)-1;
$array_type=' ';
while($types_size!=-1)
{
$array_type.='"'.$types[$types_size]["Type"]["name_type"].'", ';
$types_size--;
}
echo $array_type;
echo $this -> form -> input ('id_type', array('options' => array($array_type)));
echo $this -> form -> input ('id_type', array('options' => array(shoes, shirts, jeans,)));
?>
问题:上面的代码没有像我预期的那样显示。第一个输入的组合框只显示一个值:鞋子,衬衫,牛仔裤,不像预期的第二个输入
希望有人理解我的问题!!!
答案 0 :(得分:1)
在上面的代码中,您将意识到$array_type
是一个字符串变量而不是数组。
您应该使用$array_type = array()
而不是$array_type = ''
您可以尝试打印$array_type
变量并验证它是数组还是字符串。
现在您的代码应如下所示:
<?php
$types_size=sizeof($types)-1;
$array_type= array();
while($types_size!=-1)
{
$array_type[] = $types[$types_size]["Type"]["name_type"];
$types_size--;
}
//echo $array_type; // if you echo an array variable it will print `Array`.
//Use print_r() to print an array
print_r($array_type);
echo $this -> form -> input ('id_type', array('options' => $array_type));
echo $this -> form -> input ('id_type', array('options' => array(shoes, shirts, jeans,)));
&GT;
答案 1 :(得分:0)
<?php
$types_size=sizeof($types)-1;
$array_type= array();
while($types_size!=-1)
{
$array_type[] = $types[$types_size]["Type"]["name_type"];
$types_size--;
}
//echo $array_type; // if you echo an array variable it will print `Array`.
//Use print_r() to print an array
print_r($array_type);
echo $this -> form -> input ('id_type', array('options' => $array_type));
echo $this -> form -> input ('id_type', array('options' => array(shoes, shirts, jeans,)));