如何在PHP数组中回显日期?
通常情况下,我会使用<?php echo $date("Y")?>
,但我不知道如何将其放入数组中。
这是可能的还是不推荐这种做法?
<?php
$array= array("THIS IS WHERE I WANT TO ECHO THE CURRENT DATE", "Two", "Three");
echo . $array[0] . ", " . $cars[1] . " and " . $cars[2] . ".";
?>
答案 0 :(得分:0)
如果您已经拥有一个阵列并希望在特定位置插入,请执行以下操作:
$array= array("Object to be replaced", "Two", "Three");
$array[0] = Date('Y');
// print_r($array) will output [0] => "theDate"; [1] "Two"; [2] "three"
如果要将其推送到数组的末尾,请执行以下操作:
array_`push($array,` Date('Y');
// print_r($array) will output [0] => "Object to be replaced"; [1] "Two"; [2] "three"; [3] "theDate";