0

I have some array like this
When I use code like this :

I got this error : Notice: Undefined index: users_id in D:\xampp\htdocs\home\database\index.php on line 21

I want to call specific columns like : users_id , users_username ,etc.

If I use :

var_dump ($rowset);

I got :

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

My Code :

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

Thanks

Rahul
  • 18,271
  • 7
  • 41
  • 60
Joel
  • 47
  • 1
  • 1
  • 8
  • Possible duplicate of [PHP: "Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-notice-undefined-index-and-notice-undef) – u_mulder Mar 05 '17 at 08:55
  • What do you need to get? – apokryfos Mar 05 '17 at 08:58

2 Answers2

1

Once try like this,

foreach($rowset as $k => $v){
 echo $rowset[$k]["users_id"];
}
Rahul
  • 18,271
  • 7
  • 41
  • 60
0

you may make use of the pretty array_column :

$user_ids = array_column($rowset, 'users_id');
hassan
  • 7,812
  • 2
  • 25
  • 36