This is a collection of questions that come up every now and then about syntax in PHP. This is also a Community Wiki, so everyone is invited to participate in maintaining this list.
It used to be hard to find questions about operators and other syntax tokens.¹
The main idea is to have links to existing questions on Stack Overflow, so it's easier for us to reference them, not to copy over content from …
如果我理解正确,您可以使用以下方法为数组添加值:
$myArray[] = 123;
Run Code Online (Sandbox Code Playgroud)
要么
array_push($myArray, 123);
Run Code Online (Sandbox Code Playgroud)
一个更清洁/更快,然后另一个?
我遇到了一些看起来像这样的示例代码:
$form['#submit'][] = 'annotate_admin_settings_submit';
Run Code Online (Sandbox Code Playgroud)
为什么在['#submit']之后有一个空格,里面什么都没有?这意味着什么?谁能举个例子?通常(根据我的理解,可能是错误的)是数组有键,在这种情况下,$ form数组键'#submit'等于'annotate_admin_settings_submit'但是第二组括号的处理是什么.我见过一个数组看起来像的例子:
$form['actions']['#type'] = 'actions';
我知道这是关于php的一个非常基本的问题,但我在学习Drupal时遇到了这个问题,所以希望Drupal社区中的某个人可以澄清这个我正在痴迷的问题.