我在關聯數組中遇到了一些問題。當我檢查數組$keywordstoupdate
是否返回一個值,但是當它達到echo
時,它說Keyword
未定義。然而,print_r()
打印它,從這個角度來看一切都很好。但是當我嘗試回顯時,Keyword
丟失。關聯數組未找到指定索引
function getkeywords($mysqli, $someid)
{
$keywords=array();
$query='select Keyword from keywords where someId=?';
$stmt= $mysqli->stmt_init();
$stmt->prepare($query);
$stmt->bind_param('i', $someid);
$stmt->execute();
$stmt->bind_result($Keyword);
while($stmt->fetch())
{
$keywords[]= array("Keyword" => $Keyword);
}
return $keywords;
}
$keywordstoupdate[]=getkeywords($mysqli, $someid);
<textarea id='textarea_keywords' name='keywords'>
<?php
if(count($keywordstoupdate)>0){
for($i=0; count($keywordstoupdate)>$i; $i++){
echo ($keywordstoupdate[$i]['Keyword']." ");
}
} ?></textarea>
的print_r()
Array
(
[0] => Array
(
[Keyword] => asdf
)
)
什麼變量是'的print_r()'顯示? –
是否打印過$ keywordstoupdate? –
是的...這是'$ keywordstoupdate'的結果..順便說一句,我想我已經得到了答案.. – whatever