correct name for a variable users_ids vs user_ids

Grammatically, userIds or user_ids would be most familiar to English speakers.

However- you'll often see something like usersId if it refers to a column id on a table users, especially as it relates to foreign key relationships.

Consider:

orders.id

orders.users_id <-> users.id

As it pertains to an array of user IDs that doesn't really 'translate' to a specific object relationship in your data store, $userIds. (or $user_ids if you insist ;)


user_ids - you have not one user_id but a few.

users_id - many users have a same ID (you are in trouble if that happens...).


$user_ids is the most common. My reasons are:

  • you have multiple ids so users_id is incorrect
  • users_ids sounds awkward
  • PHP variables generally do not use camelCase

$user_ids because it refers to a list of ids (plural), each belonging to a single user (singular). When looping through the ids I often use something like the following:

$user_ids = array(12, 43, 12, 53);

foreach($user_ids as $user_id) {
// at this point $user_id refers to one id for one user
}

Besides, $user_ids is the most commonly used form (that I've seen).