可能重复:
PHP 获取数组值和数组键
我正在使用 Codeigniters 的 form_checkbox() 方法。
使用 foreach 循环我正在创建 form_checkbox 和表单的标签。这一切都很好,但我需要从数组中获取值。
我的阵列设置如下:
Array
(
[1] => Animals
[2] => Art and Culture
[3] => Children
[4] => Disability
[5] => Disaster Relief
[6] => Domestic Violence
);
我的 PHP 代码如下:
<?php foreach($interests as $interest)
{
echo form_checkbox('user_interests[]', $interest);
echo "<label>$interest</label>";
}
?>
这会产生 HTML Like :
<input type="checkbox" value="Animals" name="user_interests[]">
我希望它是 Array 键中的 value = "1"、"2" 等。
我怎么得到这个?