PHP arrays... What is/are the meaning(s) of an empty bracket?(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'
.
这篇关于PHP 数组...空括号的含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP 数组...空括号的含义是什么?


- PHP - if 语句中的倒序 2021-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01