本文介绍了您是将数组命名为复数还是单数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我命名数组类型的变量时,我经常遇到一个难题:我是将数组命名为复数还是单数?

When I'm naming array-type variables, I often am confronted with a dilemma:Do I name my array plurally or singularly?

例如,假设我有一个名称数组:在PHP中,我会说:$names=array("Alice","Bobby","Charles");但是,可以说我想在此数组中引用一个名称.对于Bobby,我会说:$names[1].但是,这接缝违反直觉.我宁愿叫Bobby $name[1],因为Bobby只是一个名字.

For example, let's say I have an array of names: In PHP I would say: $names=array("Alice","Bobby","Charles");However, then lets say I want to reference a name in this array. For Bobby, I'd say: $names[1]. However, this seams counter-intuitive. I'd rather call Bobby $name[1], because Bobby is only one name.

因此,您会看到一点差异.有命名数组的约定吗?

So, you can see a slight discrepancy. Are there conventions for naming arrays?

推荐答案

我使用复数形式.然后我可以做类似的事情:

I use the plural form. Then I can do something like:

$name = $names[1];

这篇关于您是将数组命名为复数还是单数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 06:17