Çok boyutlu bir dizi

0 Cevap

Sadece bu çözüm olduğuna inanıyoruz bir sorun rastlamak var.

Şu anda ben aşağıdaki kodu var:

function siteUsers()
{
    global $database;
    $q = "SELECT username, id FROM ".TBL_USERS."";
    return mysql_query($q, $this->connection);
}

function generateUserArray() 
{
    $u = array();
    $i = array();
    $result = $this->siteUsers();
    while( $row=mysql_fetch_assoc($result)) 
    {
        $u[] = $row['username'];
        $i[] = $row['id'];
    }
    return $u, $i;
}

As you can see, when I then go onto use foreach, the u and i get split apart. Is there anyway that I could keep them together?

foreach ($u as $username) {
  echo"<option value='$i'>$username</option>";
}

What I need it the option value to be the id and the visual value to be the username. Is this possible? Thanks

0 Cevap