php - PHP Documentor 中的注释关联数组

标签 php arrays associative-array phpdoc

我在我的 PHP 应用程序中使用了几个关联数组,并且我正在使用 PHP 文档器来注释我的源代码。我从来没有真正为数组中的数组指定注释,但现在我需要这样做并且不知道如何。

$array = array('id' => 'test', 'class' => 'tester', 'options' => array('option1' => 1, 'option2' => 2))

对于 @var@param 注释,如何以正确的方式注释此数组? 我可以这样做,但我不知道这是否正确:

@param string $array['id']
@param string $array['class']
@param int $array['options']['option1']

但是如何为 @var 部分执行此操作?

最佳答案

您无法记录每个键,但是 you can tell phpDocumentor what type it is .

你可以这样做:

/**
 * Form the array like this:
 * <code>
 * $array = array(
 *   'id'      => 'foo',          // the id
 *   'class'   => 'myClass',     // the class
 * );
 * 
 * </code>
 *
 * @var array[string]string 
 */
$array;

关于php - PHP Documentor 中的注释关联数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2713710/

相关文章:

php - 以位为单位保护随机十六进制大小以防止暴力破解

php - php变量,字符串和数组:关联数组返回字符串的第一个字母

php - 如何在多维数组中插入新的键和值?

javascript - 如何在 javascript 中连接两个数组?

python - 从字典中提取键值对的子集?

php - CodeIgniter Ion_auth 检查登录

php - 如何正确发送小数到mysql数据库?

php - array_push 在函数中不起作用,PHP

java - 在单独的类中访问私有(private)变量?

java - JButton 位于 JPanel 上,但它不应该位于 JPanel 上