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 数组...空括号的含义是什么?
基础教程推荐
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- HTTP 与 FTP 上传 2021-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- PHP 守护进程/worker 环境 2022-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- 使用 PDO 转义列名 2021-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01