Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.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
Codeigniter 阵列未重置_Codeigniter_Multidimensional Array_Associative Array - Fatal编程技术网

Codeigniter 阵列未重置

Codeigniter 阵列未重置,codeigniter,multidimensional-array,associative-array,Codeigniter,Multidimensional Array,Associative Array,我的php中有一个循环,它获取两个表的数据库值,并将它们显示在CodeIgniter下拉列表中-但是数组在news_types循环后不会自行重置,而是使用类别数据…有人能帮我吗 谢谢 //inside a loop if(isset($news_types)) { foreach($news_types as $type) { $options[$type['id']] = ucwords($type['type']); } } if(isset($categorie

我的php中有一个循环,它获取两个表的数据库值,并将它们显示在CodeIgniter下拉列表中-但是数组在news_types循环后不会自行重置,而是使用类别数据…有人能帮我吗

谢谢

//inside a loop

if(isset($news_types)) {
   foreach($news_types as $type) {
      $options[$type['id']] = ucwords($type['type']);
   }
}

if(isset($categories)) {
   foreach($categories as $category) {
      $options[$category['id']] = ucwords($category['category']);
   }
}

echo '<p>';
echo format_label($field);
echo form_dropdown($field, $options, check_value($field, $submitted, $record->$field));
echo '</p>';
//在循环中
如果(isset($news_types)){
foreach($news\u类型为$type){
$options[$type['id']=ucwords($type['type']);
}
}
if(isset(类别)){
foreach($categories作为$category){
$options[$category['id']=ucwords($category['category']);
}
}
回声“”;
回波格式\u标签($field);
echo form_下拉菜单($field,$options,check_value($field,$submitted,$record->$field));
回声“

”;
如果您的新闻类型id与类别id匹配,它们将被覆盖。。。试试这个来验证

if(isset($news_types)) {
   foreach($news_types as $type) {
      $options["news_".$type['id']] = ucwords($type['type']);
   }
}

if(isset($categories)) {
   foreach($categories as $category) {
      $options["cat_".$category['id']] = ucwords($category['category']);
   }
}
为ID添加前缀以确保它们不会冲突