Explicit Key Specification in PHP
If necessary, keys can be specified explicitly:
<?php
$arr = []; // create an empty array
$arr[0] = 'a'; // add element 'a' to key 0
$arr[1] = 'b'; // add element 'b' to key 1
$arr[2] = 'c'; // add element 'c' to key 2
var_dump($arr); // will output ['a', 'b', 'c']
?>
Keys can be not only numeric, but also string:
<?php
$arr = [];
$arr['a'] = 1;
$arr['b'] = 2;
$arr['c'] = 3;
var_dump($arr); // will output ['a' => 1, 'b' => 2, 'c' => 3]
?>
Given an empty array:
<?php
$arr = [];
?>
Using the described method, write the current year to the key 'year'
,
the current month to the key 'month'
, and the current
day to the key 'day'
.