美好的一天,我正试着save
到我的桌子。
function save()
{
extract(populateform());
echo "<pre>";print_r(populateform());
$tipenya = $this->modelmodel->showdata("SELECT * From user_type");
foreach($tipenya as $types)
{
if($pilihan[$types->id_tipe] != ''){
foreach($pilihan[$types->id_tipe] as $values){
echo "insert into tbl a value ('".$values.','.$types->id_tipe."')<br>";
}
}
}
}
这是我要保存的数据
Array
(
[pilihan] => Array
(
[TP001] => Array
(
[0] => 2
)
[TP003] => Array
(
[0] => 2
)
)
)
print_r($tipenya)
Array
(
[0] => stdClass Object
(
[id_tipe] => TP001
[deskripsi] => Developer
[flag] => 1
)
[1] => stdClass Object
(
[id_tipe] => TP002
[deskripsi] => Admin
[flag] => 1
)
[2] => stdClass Object
(
[id_tipe] => TP003
[deskripsi] => Outlet
[flag] => 1
)
)
这是错误Message: Undefined index: TP002
。但是当我尝试输入这个
Array
(
[pilihan] => Array
(
[TP001] => Array
(
[0] => 1
)
[TP002] => Array
(
[0] => 1
)
[TP003] => Array
(
[0] => 1
)
)
)
没有任何错误。我正在尝试使用它,但没有帮助
if($pilihan[$types->id_tipe] != ''){ }
答案 0 :(得分:0)
使用isset()
:
if (isset($pilihan[$types->id_tipe])) {
答案 1 :(得分:0)
使用isset()
检查您的索引是否已设置。
Isset
只是检查它是否设置,它可以是任何不为空的
if(isset($pilihan[$types->id_tipe]) && $pilihan[$types->id_tipe] != ''){
或强>
Empty
检查变量是否已设置,如果是,则将其检查为null,“”,0等
if(!empty($pilihan[$types->id_tipe]))