2017-03-05 35 views
0

我有一些陣列這樣
當我使用這樣的代碼:
呼叫特定列在陣列

我得到這個錯誤:在 d users_id::通知:未定義指數\ XAMPP \ htdocs中\ home \ database \ index.php on line 21

我想調用特定的列,如users_id,users_username等。

如果我使用:

var_dump ($rowset); 

我:

Array ([0] => Array ([users_id] => 1 [users_username] => admin [users_password] => admin 

我的代碼:

$rowset = array(); 
    while ($row = $sql->fetch(PDO::FETCH_ASSOC)){ `enter code here` 
     $rowset[] = $row; 
    } 
     echo $rowset["users_id"];// Line 21 

感謝

+0

[PHP的可能重複: 「請注意:未定義的變量」, 「通知:未定義指數」 和「注意:Undefined offset「](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-notice-undefined-index-and-notice-undef) –

+0

你需要得到什麼? – apokryfos

回答

1

一旦嘗試這樣,

foreach($rowset as $k => $v){ 
echo $rowset[$k]["users_id"]; 
} 
+0

然後,我就只是一個users_id – Joel

+0

再使用的foreach,檢查答案再次 – rahulsm

+0

哦,是的,由於它會真:* – Joel

0

你可以利用漂亮的array_column的:

$user_ids = array_column($rowset, 'users_id');