无法理解PHP关联数组的价值

时间:2016-07-07 04:13:37

标签: php arrays wordpress

我无法理解关联数组的最后一个值'changes' => [ ],

$table_report = array(
        'table_name' => $table,
        'rows'       => 0,
        'change'     => 0,
        'changes'    => [ ],
    );

1 个答案:

答案 0 :(得分:3)

[]是PHP 5.4中引入的array()的替代语法

[]只是一个空数组。

$table_report = array(
  'table_name' => $table,
  'rows'       => 0,
  'change'     => 0,
  'changes'    => array()
);

相当于

$table_report = [
  'table_name' => $table,
  'rows'       => 0,
  'change'     => 0,
  'changes'    => []
];