現在日付データを年月日で変数に入れる。

日付を年月日で分けて変数に入れる時に、もっとスマートな方法は無いものでしょうか。

[php]
$today = getdate();
$year = $today['year'];
$month = $today['mon'];
$day = $today['mday'];
[/php]

こんな感じで済ませちゃいますけど。うーん。

関連する記事:

Powered by

  1. 私も同じ悩みを持っています。
    とりあえず today() を用意しておけば一行で済みますが。

    list($year, $month, $day) = today();

    function today() {
    $today = getdate();
    $year = $today['year'];
    $month = $today['mon'];
    $day = $today['mday'];
    return array($year, $month, $day);
    }

  2. こんにちは!
    確かにそれ専用の関数があるとlistでスマートに行えますねー。ありがとうございます!
    ちょっと匿名関数で作ってみました。

    list($year, $month, $day) = call_user_func(
    create_function(‘$d’, ‘return array($d["year"], $d["mon"], $d["mday"]);’),
    getdate()
    );

    これは見にくいw ですね。これならlistで必要なものだけを取得したほうがスマートに見えるかもです。

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">