Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

correct name for a variable users_ids vs user_ids

I ask you, native English speakers:

What is the correct name for a variable which contains ids of multiple users (from grammar point of view):

A) users_ids vs B) user_ids

I'm pretty sure C) users_id is wrong.

The variable is an array of ids:

array(12, 43, 12, 53)

and why?

like image 539
GoTo Avatar asked Aug 25 '11 22:08

GoTo


2 Answers

$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).

like image 175
Herbert Avatar answered Oct 12 '22 16:10

Herbert


$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
like image 26
brian_d Avatar answered Oct 12 '22 16:10

brian_d