php - How to create associative array with Id and Value? -


i have table contains id , weight. want put both in associative array.

right i've managed put weight in array:

$weight= array(); $stmt = $dbc->query("select * tbl_weight"); while($row = $stmt->fetch(pdo::fetch_assoc)) {  $weight[] = $row['weight']; } 

i want put id , make associative array.

for example id = 1 , weight = 50, want able like:

$weight = array("1"=>"50"); 

how can this?

just set key when append value. long id unique shouldn't have problems

$weight= array(); $stmt = $dbc->query("select * tbl_weight"); while($row = $stmt->fetch(pdo::fetch_assoc)) {     $weight[$row['id']] = $row['weight']; } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -