PHP数组...空括号的含义是什么?
我遇到了一些看起来像这样的示例代码:
I ran across some example code that looks like this:
$form['#submit'][] = 'annotate_admin_settings_submit';
为什么 ['#submit'] 后面的括号是空的,里面什么都没有?这意味着什么?谁能给我一个例子?通常(根据我的理解,这可能是错误的)是数组有键,在这种情况下,$form 数组键 '#submit' 等于 'annotate_admin_settings_submit' 但第二组括号的处理是什么.我见过数组可能看起来像这样的示例:
Why is there a bracket after ['#submit'] that is empty with nothing inside? What does this imply? Can anyone give me an example? Normally (from my understanding which is probably wrong) is that arrays have keys and in this case the the $form array key '#submit' is equal to 'annotate_admin_settings_submit' but what is the deal with the second set of brackets. I've seen examples where an array might look like:
$form['actions']['#type'] = 'actions';
我知道这是关于 php 的一个非常基本的问题,但是我在学习 Drupal 时遇到了这个问题,所以希望 Drupal 社区中的某个人可以澄清这个我很着迷的问题.
I know this is a very basic question about php in general but I ran across this question while learning Drupal so hopefully someone in the Drupal community can clarify this question that I'm obsessing over.
推荐答案
当你说 $form['actions']['#type'] = 'actions'
时,它会为$form['actions']['#type']
,但是当你说 $form['#submit'][] = 'annotate_admin_settings_submit'
时,如果 $form['#submit']
是一个数组,它将 'annotate_admin_settings_submit'
附加到它的末尾,如果它为空,它将是一个包含一个元素的数组是 'annotate_admin_settings_submit'
.
When you say $form['actions']['#type'] = 'actions'
, it assigns a value to $form['actions']['#type']
, but when you say $form['#submit'][] = 'annotate_admin_settings_submit'
, if $form['#submit']
is an array, it appends 'annotate_admin_settings_submit'
to the end of it, and if it's empty, it will be an array with one single element that is 'annotate_admin_settings_submit'
.
相关文章