我正在處理一個數組,該數組向我提供所有信息(如果print_r但它也表示它是未識別的索引)。 代碼:即使我可以獲取數據,未定義的索引通知
foreach ($_SESSION['passo4'] as $key => $value) {
$x = $data_ref[0]['tipo_refeicao']; //gives me the error
echo $x; //echoes 1
print_r($data_ref);
if($key != 'preco'){
//Obter info do tipo de vestuário
$f_r = $dbh->prepare("SELECT tipo_refeicao, preco_acompanhante, preco_participante FROM refeicao WHERE id_extra = '$key'");
$f_r->execute();
$data_ref = $f_r->fetchAll();
echo "<tr><td>".
datasearch($data_tref, 'tipo_refeicao', $x, 'descricao')
."</td>";
echo "<td>". $value ."</td>";
echo "<td>". $data_ext[0]['preco'] * $value ."€</td></tr>";
}
}
通知
Notice: Undefined offset: 0 in C:\xampp\htdocs\Rot.Aventura\eventos\passo5.php on line 96
的print_r($ data_ref):
Array ([0] => Array ([id_refeicao] => 4 [id_evento] => 11 [tipo_refeicao] => 1 [preco_participante] => 5 [preco_acompanhante] => 6 [limite_pessoa] => 2))
模具($ X):1
我應該隱藏與本通知@或有什麼辦法可以解決這個問題嗎? (對不起,葡萄牙語單詞)
post'print_r($ data_ref)'看得更清楚 – Saqueib 2014-10-01 11:33:16
將'[0]'留在代碼之外。 – Daan 2014-10-01 11:34:18
這是一個循環嗎? – senK 2014-10-01 11:34:52