沃梦达 / 编程问答 / php问题 / 正文

PHP数组...空括号的含义是什么?

PHP arrays... What is/are the meaning(s) of an empty bracket?(PHP数组...空括号的含义是什么?)

本文介绍了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数组...空括号的含义是什么?

基础教程推荐