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
Post a Comment