2
I’m trying to use this script, which returns every Monday between two periods:
$beginday = isset($_POST["Tinsem3"]) ? $_POST["Tinsem3"] : false;
$lastday = isset($_POST["Tdesl"]) ? $_POST["Tdesl"] : false;
$lastday = strtotime($lastday);
for($i = strtotime('Monday', strtotime($beginday)); $i <= $lastday; $i = strtotime('+1 week', $i))
echo date('l Y-m-d', $i);
I adapted to search the form data, and output between dates 08/04/2015
and 08/05/2015
is already correct:
Monday 2015-04-13
Monday 2015-04-20
Monday 2015-04-27
Monday 2015-05-04
What I want is to put each of these results within variables, so I can count how many seconds there are and use to do some calculations.
I’ve tried to do something like:
$tornararray = array (date('l Y-m-d', $i));
And then count the arrays
, with something like:
$total2 = count(array_filter($tornararray));
But when do I give var_dump
of $tornararray
, I get the exit:
array(1) { [0]=> string(17) "Monday 2015-05-04" }
From what I understand, he’s only picking up the last occurrence. How do I turn each of the results I get with echo date('l Y-m-d', $i);
in variables?
Warning: This question is is not duplicate of this. These are different questions. Here I want to know how to include the results (from another script, not the one used in that question) within variables, while in that other one I have very different goals (adapt that working day script etc...).
Only one addendum: array_push has the same effect as
$array[] = $var
- see the manual!– Papa Charlie
Yes. It’s true, @Papa Charlie. It’s even better to do this, because of preprocessing.
– Diego Souza
Yes, and in the end you’ll have to use
count
to count the items - it is inevitable– Papa Charlie
I tested it here and the two solutions worked! + 1 Dei as solved on @Papacharlie for having already included the count. Thanks to both!
– gustavox