Insert current year variable into PHP array

Here is the code I have in WordPress template’s PHP file with some variables. Actually it is a stripped down replica of Warp Framework’s warp/config.php.

<?php
return array(
    'month' => 'Current month',
    'year' => 'Current year'
);

Is it possible to replace Current month and Current year texts with actual PHP date output?

Read More

I know how to implement PHP date into a PHP page but I have no idea how to place it here.

Related posts

Leave a Reply

2 comments

  1. Try this

    <?php
        return array(
            'month' => date('m'),
            'year' => date('Y')
        );
    ?>
    

    That should give you what you need.
    Basically, using PHP’s date() function, you can output the current date in whichever format you need by specifying the format mask in it’s instantiation.

    This page of the PHP.net site will help explain the many different methods of creating a date. PHP.net date() Function

  2. If the previous code creates an array called for instance $date and you just want to change it after it was created, you could do so as follows:

    $date['month'] = date('m');
    $date['year'] = date('Y');
    

    If however you want to modify the code that is creating the array, then guyver4mk’s answer is on point:

    <?php
    return array(
        'month' => date('m'),
        'year' => date('Y')
    );
    ?>