Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I suppose a solution would be to start by getting the timestamp that correspond to last monday, using <a href="http://php.net/strtotime" rel="nofollow noreferrer"><code>strtotime</code></a> :</p> <pre><code>$timestampFirstDay = strtotime('last monday'); </code></pre> <p><br> But if you try with today <em>(thursday)</em>, with something like this :</p> <pre><code>$timestampFirstDay = strtotime('last thursday'); var_dump(date('Y-m-d', $timestampFirstDay)); </code></pre> <p>you'll get :</p> <pre><code>string '2010-02-18' (length=10) </code></pre> <p>i.e. last week... For strtotime, <em>"last"</em> means <em>"the one before today"</em>.</p> <p>Which mean you'll have to test if today is <em>"last monday"</em> as returned by <code>strtotime</code> plus one week -- and, if so, add one week...</p> <p>Here's a possible <em>(there are probably smarter ideas)</em> solution :</p> <pre><code>$timestampFirstDay = strtotime('last monday'); if (date('Y-m-d', $timestampFirstDay) == date('Y-m-d', time() - 7*24*3600)) { // we are that day... =&gt; add one week $timestampFirstDay += 7 * 24 * 3600; } </code></pre> <p><br> And now that we have the timestamp of <em>"last monday"</em>, we can write a simple <code>for</code> loop that loops 7 times, adding 1 day each time, like this :</p> <pre><code>$currentDay = $timestampFirstDay; for ($i = 0 ; $i &lt; 7 ; $i++) { echo date('Y-m-d', $currentDay) . '&lt;br /&gt;'; $currentDay += 24 * 3600; } </code></pre> <p>Which will give us this kind of output :</p> <pre><code>2010-02-22 2010-02-23 2010-02-24 2010-02-25 2010-02-26 2010-02-27 2010-02-28 </code></pre> <p><br> Now, up to you to :</p> <ul> <li>Modify that <code>for</code> loop so it stores the dates in an array</li> <li>Decide which format you want to use for the <a href="http://php.net/manual/en/function.date.php" rel="nofollow noreferrer"><code>date</code></a> function</li> </ul> <p>Have fun ;-)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload