Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
以下のコードでは、最後の pr_name をすべてのキーに割り当てているという問題があります。
$arr = array(); while($row = mysql_fetch_array($results)) { $keys[] = $row['pr_code']; $items = array_fill_keys($keys, $row['pr_name']); }
これで簡単に:
$items = array(); while($row = mysql_fetch_array($results)) { $items[$row['pr_code']] = $row['pr_name']; }