Jump to content

Can I input data like this in an associative array?


3raser

Recommended Posts

$array = array();

while($row = mysql_fetch_assoc($query))
{
array_merge(postcount($row['username']) => $row['username'].':'.$row['lastlogin']);
}

 

Is this possible? It returns:

 

Parse error: syntax error, unexpected T_DOUBLE_ARROW in /homepages/31/d396088066/htdocs/forums/rankings.php on line 67

 

Thanks!

$array[] = array(postcount($row['username']) => $row['username'].':'.$row['lastlogin']);

 

Creates a new entry for each user in $array. To be able to access postcount, username, and such in an easy way it's best to use:

$array[] = array('postcount' => postcount($row['username']), 'username' => $row['username'], 'lastlogin' => $row['lastlogin']);

 

Acessing the first player's postcount:

$array[0]['postcount'];

 

While you would have to get creative with the example at the top of this post to get the same info:

key($array[0]);

$array[] = array(postcount($row['username']) => $row['username'].':'.$row['lastlogin']);

 

Creates a new entry for each user in $array. To be able to access postcount, username, and such in an easy way it's best to use:

$array[] = array('postcount' => postcount($row['username']), 'username' => $row['username'], 'lastlogin' => $row['lastlogin']);

 

Acessing the first player's postcount:

$array[0]['postcount'];

 

While you would have to get creative with the example at the top of this post to get the same info:

key($array[0]);

 

Thanks! That's a creative way to do it. I appreciate you taking the time to help out.  :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.